Iは、名前とバランスのフィールドが二つの異なる配列から来ているrecyclerView、RecyclerView EditTextから値を取得しますか?
ここに打たれています。 必要なのは、各行にEditTextフィールドがあることです。私は各行の各EditTextにアクセスする必要があります。それから値を取得し、totalはtotal textViewに表示されます。出来ますか?私はたくさん試しました。私はそれを得ていない。
私はここに私のクラスを付けています。
MainActivity
public class GroupCollectionFragment extends Fragment {
String[] nameArray = {"Akhil","Mohan","Anoop","Syam","Athul","Anish","Anand","Prasad","Mani","Oommen"
,"Akhil","Mohan","Anoop","Syam","Athul","Anish","Anand","Prasad","Mani","Oommen"
,"Akhil","Mohan","Anoop","Syam","Athul","Anish","Anand","Prasad","Mani","Oommen"};
String[] balanceArray={"2354","6578","2345","34654","2542","2354","6578","2345","34654","2542"
,"2354","6578","2345","34654","2542","2354","6578","2345","34654","2542"
,"2354","6578","2345","34654","2542","2354","6578","2345","34654","2542"};
RecyclerView mRecyclerView;
RecyclerView.Adapter mAdapter;
LinearLayoutManager mLayoutManager;
List<DataHolder> holderList=new ArrayList<DataHolder>();
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootview=inflater.inflate(R.layout.group_collection_layout,container,false);
mRecyclerView = (RecyclerView) rootview.findViewById(R.id.my_recycler_view);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getContext());
mRecyclerView.setLayoutManager(mLayoutManager);
setItems();
mAdapter = new Adapter(holderList);
mRecyclerView.setAdapter(mAdapter);
return rootview;
}
private void setItems() {
for(int i=0;i<nameArray.length;i++){
DataHolder item=new DataHolder();
item.setDname(nameArray[i]);
item.setDbalance(balanceArray[i]);
holderList.add(item);
}
}
}
DataHolder
public class DataHolder {
String dname,dbalance;
public DataHolder(){
}
public String getDname(){
return dname;
}
public void setDname(String name){
this.dname=name;
}
public String getDbalance(){
return dbalance;
}
public void setDbalance(String balance){
this.dbalance=balance;
}
}
アダプタ
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
private List<DataHolder> mDataSet;
public static class ViewHolder extends RecyclerView.ViewHolder{
private TextView anameTxtView,abalanceTxtView;
private EditText adepositEditText;
public ViewHolder(View v){
super(v);
anameTxtView=(TextView)v.findViewById(R.id.nameTextView);
abalanceTxtView=(TextView)v.findViewById(R.id.balanceTextView);
adepositEditText=(EditText)v.findViewById(R.id.depositEditText);
}
}
public Adapter(List<DataHolder> myData){
mDataSet=myData;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v=LayoutInflater.from(parent.getContext()).inflate(R.layout.row_main,parent,false);
ViewHolder vh=new ViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.anameTxtView.setText(mDataSet.get(position).getDname());
holder.abalanceTxtView.setText(mDataSet.get(position).getDbalance());
}
@Override
public int getItemCount() {
return mDataSet.size();
}
@Override
public int getItemViewType(int position) {
return position;
}
}
ありがとうございます!私はそれを通って行くよ! :)また、私はそれが必要です – BraveHeart
@BraveHeart 私の答えを受け入れるでしょうか? :テキストが削除されたときにD Adapter.java http://paste.ubuntu.com/24221230/ GroupCollectionFragment.java http://paste.ubuntu.com/24221236/ – MeHdi
私はどこ、ヌル例外の問題を持っていますそれが空の場合にチェックする必要がありますか? –