прослушиватель кликов не работает, когда я нажимаю элемент.ListView setOnItemClickListener не запускает
в этой программе первые два arraylist обновлены с помощью update(). то это представление списка отправляется в другой класс для создания списка. но нажатие каждого пункта ничего не тост.
public class BlockActivity extends Activity {
ListView lv;
ArrayList<String> contactnumber= new ArrayList<String>();
ArrayList<String> contactname= new ArrayList<String>();
public static SQLiteDatabase database;
SQLiteDatabase myDB= null;
CustomAdapter adapter;
ArrayList<String> contactnum= new ArrayList<String>();
ArrayList<String> contactnam= new ArrayList<String>();
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button pickContact = (Button) findViewById(R.id.button1);
update();
lv=(ListView) findViewById(R.id.listView1);
adapter = new CustomAdapter(this, contactnam, contactnum);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id)
{
/*new AlertDialog.Builder(view.getContext())
.setMessage("Something here")
.setNegativeButton("Close", null).show();*/
Toast.makeText(BlockActivity.this,
"Item in position " + position + " clicked", Toast.LENGTH_LONG).show();
}
});
pickContact.setOnClickListener(new OnClickListener() {
.
.
.
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="add" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
detail.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:focusableInTouchMode="false" android:focusable="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_weight="1" android:focusable="false" android:focusableInTouchMode="false">
<Button android:id="@+id/button2" android:layout_width="0dp" android:layout_height="wrap_content" android:text="Button"/>
<TextView
android:id="@+id/one"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="name"
android:textSize="20dip" android:layout_gravity="center" android:focusable="false" android:focusableInTouchMode="false"/>
<TextView
android:id="@+id/two"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="name"
android:textSize="20dip" android:layout_gravity="center" android:focusable="false" android:focusableInTouchMode="false"/>
</LinearLayout>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="2dip" android:background="#ff7f7f"/>
"Детальный.xml" для элементов списка? – JoeyJubb
В вашем ListView добавить 'android: focusable =" false " android: clickable =" false "' –
положить в элемент макет android: focusable = "false" – Pavan