Я пытаюсь получить событие OnClick для кнопки внутри ListView, но это не работаетКнопка setOnClickListener в ListView
fragment_contact.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="404dp"
android:layout_weight="0.64"
android:orientation="horizontal"
android:paddingBottom="40dip" >
<ListView
android:id="@+id/contactlistview"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="fill"
android:layout_weight="10"
android:textSize="5pt"
android:visibility="visible" />
</LinearLayout>
fragment_contact_content.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"
android:weightSum="1">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/btn_edit_contact"
android:layout_gravity="right" />
</LinearLayout>
FragmentContact.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_contact, container, false);
ListAdapter adapter_contact = new SimpleAdapter(
getActivity(), allcontact,
R.layout.fragment_contact_content, new String[]{"name", "level", "function", "phone", "email"},
new int[]{R.id.contact, R.id.level, R.id.function, R.id.phone, R.id.email});
listview_contact = (ListView) view.findViewById(R.id.contactlistview);
listview_contact.setItemsCanFocus(true);
listview_contact.setAdapter(adapter_contact);
Button btn_edit_contact = (Button) view.findViewById(R.id.btn_edit_contact);
btn_edit_contact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("Do something");
}
});
return view;
}
Я также попытался накачивания fragment_contact_content.xml но кнопка все еще ничего не делает.
Вы должны сделать это в GetView() из списка адаптер класса – Prasad
список настроек с адаптером, а затем установить кнопку мыши в адаптере –
я уже сделал установку на список с адаптером. Я просто не включил его в приведенный выше код, потому что я думал, что это уже очевидно. Во всяком случае, попробуем getView(). Я просто не понимаю нисходящего, когда я просто пытался усердно учиться здесь. – user3360031