I have a list of items in android app, and i want to start another activity if the user clicks on any item in that list. I have the following piece of (relevant) code.
Strangely enough, its working good enough on HTC velocity 4g (android 2.3.7), whereas I have tried the same app on HTC one S (android 4.1.1) and nothing happens when i click any item in the list. Does anyone have any idea what could be the problem here???
lv = (ListView)findViewById(R.id.listView1);
this.adapter = new SimpleAdapter(DisplayWiFiListActivity.this, arraylist, R.layout.row, new String[] { ITEM_KEY }, new int[] { R.id.abcd });
lv.setAdapter(this.adapter);
// React to user clicks on item
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parentAdapter, View view, int position,
long id) {
String text = parentAdapter.getItemAtPosition(position).toString();
text = text.substring(5,text.length()-1);
Intent intent = new Intent(DisplayWiFiListActivity.this, MainActivity.class);
DisplayWiFiListActivity.this.startActivity(intent);
intent.putExtra(EXTRA_MESSAGE, text);
startActivity(intent);
Toast.makeText(DisplayWiFiListActivity.this, text, Toast.LENGTH_SHORT).show();
}
});
row.xml is following
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/abcd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:clickable="true"
android:layout_marginTop="20dp" />
</LinearLayout>
activity_display_wifi_list.xml is following
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".DisplayWiFiListActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:clickable="true"
android:layout_marginTop="100dp" >
</ListView>
<Button
android:id="@+id/buttonScan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/refresh_list" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/buttonScan"
android:textStyle="normal|italic"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"/>
</RelativeLayout>