-1

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>

  • 1
    do you have any clickable view in items of your listview?setOnItemClickListener dont work for listview if you have a clickable view same button in item's view of listview – zohreh Dec 01 '13 at 04:06
  • I couldn't understand your comment completely .. i am displaying a list of available WiFi networks .. do i have to make them clickable in xml? and how? i have made it selectable by android:textIsSelectable="true".. the thing that is confusing me is that its working perfectly fine in HTC velocity – user2904943 Dec 01 '13 at 10:56
  • I have added xml to my question.. please take a look – user2904943 Dec 01 '13 at 11:24

1 Answers1

0

Please post your code of SimpleAdapter or if you have any Button Widget in listitem layout pls make it focus-able false;

Vipin Sahu
  • 1,441
  • 1
  • 18
  • 29