Note that there are some explanatory texts on larger screens.

plurals
  1. POwrong formating in custom android listView
    primarykey
    data
    text
    <p>I have my simple custom listview layout defined in XML. sometimes after edditing content of this listview and after calling method listviewAdapter.notifyDataSetChanged(); I got my listview distorted: </p> <p><img src="https://i.stack.imgur.com/A50mQ.png" alt="enter image description here"></p> <p>in this snapshot the first entry in a list view should be centred like rest of the entries. this happens in the random position in the listview... Here goes XML definition of the listview...</p> <pre><code> &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/Black" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" tools:context=".MainActivity" &gt; &lt;View android:id="@+id/remelis1" android:layout_width="wrap_content" android:layout_height="3dp" android:layout_alignLeft="@+id/Gaminys" android:layout_alignParentTop="true" android:background="@drawable/remelis" /&gt; &lt;TextView android:id="@+id/Gaminys" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/remelis1" android:layout_centerHorizontal="true" android:gravity="center" android:padding="@dimen/dp2" android:text="Large Text" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/Orange" /&gt; &lt;TextView android:id="@+id/plotis" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/Gaminys" android:layout_below="@+id/Gaminys" android:gravity="right" android:paddingBottom="@dimen/dp2" android:paddingLeft="@dimen/dp2" android:paddingRight="@dimen/dp2" android:paddingTop="@dimen/dp2" android:text="Small Text" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/Orange" /&gt; </code></pre> <p></p> <p>EDIT: I define listView items and adapter in fallowing way:</p> <pre><code> String[] gaminiai = new String []{ "040 319 00", "040 342 00", "040 419 00", " 040 565 00", "040 566 00", "040 792 00", "040 847 00", " 041 082 00", "041 283 00", "041 284 00", "041 400 00", "041 800 00"}; double [] plotis = new double [] {160.0 , 190.5, 185.3 , 90.0, 252.0, 190.0, 302.3, 140.8, 55.5, 100.0 , 110.5 , 125.0 }; for (int i=0; i&lt;=11; i++){ arrayWidith.add(new Plotis(gaminiai[i], plotis[i])); } widithAdapter = new myAdapter(this, R.layout.my_list_view, arrayWidith); myListView.setAdapter(widithAdapter); </code></pre> <p>Listener for a listview:</p> <pre><code> myListView.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView&lt;?&gt; arg0, View arg1, int pos, long id) { arrayWidith.remove(pos); widithAdapter.notifyDataSetChanged(); return true; } }); </code></pre> <p>"Plotis" is my Class representin object with two fields - string and double. myAdapter is basicly copy/paste from some tutorial from the web and it is defined like this:</p> <pre><code> public class myAdapter extends ArrayAdapter { Context mContext; int layoutResourceId; ArrayList&lt;Plotis&gt; mData = null; public myAdapter(Context mContext, int layoutResourceId, ArrayList&lt;Plotis&gt; data) { super(mContext, layoutResourceId, this.layoutResourceId = layoutResourceId; this.mContext = mContext; mData = data; } @Override public View getView(int position, View convertView, ViewGroup if(convertView==null){ // inflate the layout LayoutInflater inflater = ((Activity) mContext).getLayoutInflater(); convertView = inflater.inflate(layoutResourceId, parent, false); } Plotis plotis = mData.get(position); // get the TextView and then set the text (item name) and tag (item ID) values TextView textViewItem = (TextView) convertView.findViewById(R.id.Gaminys); textViewItem.setText(plotis.getStringGaminys()); textViewItem = (TextView) convertView.findViewById(R.id.plotis); textViewItem.setText(plotis.getStringPlotis()); return convertView; } } </code></pre> <p>What did I do wrong?? thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload