我没有足够的知识来解决我的问题。在我问之前,我一直在寻找答案并尝试了各种选择。
我有 ListView 和 setOnItemClickListener:
新版本,只有 ListItem 和 setOnItemClickListener activity_main
<?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="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/listView">
</ListView>
</RelativeLayout>
物品
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:ems="10"
android:id="@+id/editText"
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:ems="10"
android:id="@+id/editText1"
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false"/>
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false"/>
</LinearLayout>
mainActivity、NoteItems、NoteItemsAdapter
public class MainActivity extends Activity {
ListView listView;
List<NotesItems> list;
private NoteItemsAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list= new ArrayList<NotesItems>();
list.add(new NotesItems(0, "",",",",", ""));
listView= (ListView) findViewById(R.id.listView);
adapter = new NoteItemsAdapter(this, list);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapter, View itemClicked, int position, long id) {
Toast.makeText(itemClicked.getContext(), "Work", Toast.LENGTH_LONG).show();
}
});
}
}
public class NotesItems {
private long id;
private String title;
private String description;
private String fileName;
private String packageName;
public NotesItems(int id, String title, String description, String fileName, String packageName){
this.description = description;
this.title = title;
this.id = id;
this.fileName=fileName;
this.packageName = packageName;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getPackageName(){return packageName;}
public String getNoteTitle() {
return title;
}
public String getFileName() {return fileName;}
public void setFileName(String fileName) {this.fileName = fileName;}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
public class NoteItemsAdapter extends BaseAdapter {
Context context;
private LayoutInflater layoutInflater;
private List<NotesItems> items;
public NoteItemsAdapter(Context view, List<NotesItems> list){
this.context = view;
this.items = list;
this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int i) {
return items.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
View view = convertView;
if(view == null){
view = layoutInflater.inflate(R.layout.item, viewGroup, false);
}
final NotesItems notesItems = getNoteItem(i);
EditText editText1= (EditText)view.findViewById(R.id.editText);
editText1.setText(notesItems.getDescription());
EditText editText2= (EditText)view.findViewById(R.id.editText1);
editText2.setText(notesItems.getNoteTitle());
return view;
}
private NotesItems getNoteItem(int position){
return (NotesItems) getItem(position);
}
}
我添加了 TextView 进行测试:如果单击 EditText - 没有任何反应,如果单击 TextView - 出现吐司。
我需要使 EditText 看起来像 TextView - 当您单击 listItem 上的任意位置时,必须出现吐司。