Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid listview behaving randomly
    primarykey
    data
    text
    <p><br> I am facing problem with listview i-e i am inflating some view on ListViewItem in runtime which results in increase in the ListView Row,i-e some rows in listview have different heights and others have different which is giving wrong getView position.</p> <pre><code>import android.os.Bundle; import android.view.View; import android.widget.ListView; import android.app.Activity; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView listView = (ListView) findViewById(R.id.listView1); TestAdapter adapter = new TestAdapter(this); listView.setAdapter(adapter); } public void onClickAction(View v){ v.findViewById(R.id.l1).setVisibility(View.VISIBLE); } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; public class TestAdapter extends BaseAdapter { private String[] items = {"a","b","c","d","e","f","g","h","i"}; private Context context; public TestAdapter(Context context) { this.context = context; } @Override public int getCount() { // TODO Auto-generated method stub return items.length; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return items[position]; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } ViewHolder holder; @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if(convertView == null){ convertView = LayoutInflater.from(context).inflate(R.layout.list_view_item, null); holder = new ViewHolder(); holder.textView = (TextView) convertView.findViewById(R.id.textView1); convertView.setTag(holder); }else{ holder = (ViewHolder) convertView.getTag(); } holder.textView.setText("value = "+position); return convertView; } static class ViewHolder{ TextView textView; } } &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="match_parent" tools:context=".MainActivity" &gt; &lt;ListView android:id="@+id/listView1" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;/ListView&gt; </code></pre> <p></p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/mainLayout" android:onClick="onClickAction" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Large Text" android:textAppearance="?android:attr/textAppearanceLarge" /&gt; &lt;LinearLayout android:id="@+id/l1" android:layout_width="fill_parent" android:layout_height="250dp" android:layout_alignParentLeft="true" android:layout_below="@+id/textView1" android:visibility="gone" android:background="@android:color/darker_gray" android:orientation="vertical" &gt; &lt;/LinearLayout&gt; &lt;/RelativeLayout&gt; </code></pre>
    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.
 

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