我不是很擅長android編程。我可以用cardview和recyclerview做這個佈局。Cardview與editText和Recyclerview
但我需要有一個2監聽每個卡EDITTEXT。 OnFocusChange偵聽器和OnTextChange偵聽器。我必須得到每個editText的文本。 我要做什麼? 這是我當前的代碼:
對象:
public class unitObject {
private String mtitle;
private String mhint;
unitObject(String title, String hint){
mtitle=title;
mhint=hint;
}
public String getMtitle() {
return mtitle;
}
public String getMhint() {
return mhint;
}
public void setMtitle(String mtitle) {
this.mtitle = mtitle;
}
public void setMhint(String mhint) {
this.mhint = mhint;
}
}
回收站適配器:
public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.DataObjectHolder> {
private static String LOG_TAG = "MyRecyclerViewAdapter";
private ArrayList<unitObject> mDataset;
private static MyClickListener myClickListener;
public static class DataObjectHolder extends RecyclerView.ViewHolder
implements View
.OnClickListener {
TextView title;
TextView ET_hint;
String content;
public DataObjectHolder(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.textView);
ET_hint = (TextView) itemView.findViewById(R.id.editText);
Log.i(LOG_TAG, "Adding Listener");
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
myClickListener.onItemClick(getAdapterPosition(), v);
}
}
public MyRecyclerViewAdapter(ArrayList<unitObject> myDataset) {
mDataset = myDataset;
}
@Override
public DataObjectHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.card_view_row, parent, false);
DataObjectHolder dataObjectHolder = new DataObjectHolder(view);
return dataObjectHolder;
}
@Override
public void onBindViewHolder(DataObjectHolder holder, int position) {
holder.title.setText(mDataset.get(position).getMtitle());
holder.ET_hint.setHint(mDataset.get(position).getMhint());
}
@Override
public int getItemCount() {
return mDataset.size();
}
public interface MyClickListener {
public void onItemClick(int position, View v);
}
類
public class classic_conversion extends AppCompatActivity {
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.classic_conversion_layout);
mRecyclerView = findViewById(R.id.my_recycler_view);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new MyRecyclerViewAdapter(getDataSet());
mRecyclerView.setAdapter(mAdapter);
}
private ArrayList<unitObject> getDataSet() {
ArrayList results = new ArrayList<unitObject>();
results.add(new unitObject("Title 1","hint 1"));
results.add(new unitObject("Title 2","hint 2"));
results.add(new unitObject("Title 3","hint 3"));
return results;
}
}
提前致謝!
您是不是想了解更多EditText? Eusóvejo itens de texto,mas nada paraarmazená-los。 Título做TextView; TextView ET_hint; –
在佈局中添加editText。但我不知道如何在代碼中添加editText監聽器。謝謝你的回覆 – Damien