0
私はこれらの質問はよく似ていますが、それらを機能させることはできませんでした。私は私の配列リスト内の各要素のためのそれの隣にボタンと配列を含むリストフラグメントを持っています。私の最終的な目標は、ユーザーがボタンをクリックしたときだけプログラムを応答させることですが、画面上のクリックを検出することさえできませんでした。私もボタンのフォーカスをfalseに設定しようとしましたが(他の質問から示唆されています)、それもうまくいきませんでした。ここに私のコードです。ここでカスタムリストのフラグメントをクリックして要素を無効にしてボタンのクリックを有効にする(Androidスタジオ)
public class ResultListFragment extends ListFragment {
private List<String> listValues, keyValues;
private String email, username;
private ArrayAdapter<String> myAdapter;
private ListView myListView;
private TextView title;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_resultlist, container, false);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
View v = getView();
myListView = getListView();
listValues = new ArrayList<String>();
myAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(),
R.layout.fragment_rowlayout, R.id.myListText, CameraActivity.resultList);
setListAdapter(myAdapter);
myAdapter.notifyDataSetChanged();
}
@Override
public void onListItemClick(ListView l, View v, final int position, long id) {
super.onListItemClick(l, v, position, id);
Log.d("blabla", "onListItemClick: clicked to : "+position);
final String delete=CameraActivity.resultList.get(position);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setCancelable(true);
builder.setTitle("DELETION");
builder.setMessage(delete + " delete it.");
builder.setPositiveButton("Onayla",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getActivity().getApplicationContext(), delete+ "has been deleted", Toast.LENGTH_SHORT).show();
CameraActivity.resultList.remove(position);
myAdapter.notifyDataSetChanged();
for(String st:CameraActivity.resultList){
Log.d("TAG", "onClick: eleman: " +st);
}
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
}
私のxmlファイルは
フラグメント結果リスト
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<ListView android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:background="@drawable/cembutton"
android:text="Yükle"
android:id="@+id/load"
android:layout_alignRight="@+id/results"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_alignParentBottom="true"
android:textColor="#ffffff"
android:textStyle="bold"/>
<TextView android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No data"/>
</RelativeLayout>
と
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
>
<TextView
android:id="@+id/myListText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:textStyle="bold"
android:textColor="#3700ff" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawable="@drawable/cembutton"
android:layout_alignParentRight="true"
android:text="Çıkart"
android:layout_marginRight="50dp"/>
</RelativeLayout>