Java Code:
PhoneListAdapter adapter = new PhoneListAdapter(this,brands,models,price);
lv=(ListView)findViewById(R.Id.listView1);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> Parent,View view, int position,
long id) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),"listview clicked", Toast.LENGTH_LONG).show();
}
});
XML:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="80dp"
android:clickable="true">
</ListView>
</RelativeLayout></LinearLayout>
I have done everything, if i push a toast with hardcoded string, it appears, but any methods of listview return null. what am i missing???
Hey Use somethid like below, if brands,models,price are arrayLists.