我有一個自定義listView與editText在每一行進行價值輸入的用戶。 ,並且我在列表視圖旁邊有一個按鈕,onclick會將列表中所有行的editText值加起來。android-自定義listview與edittext
任何人都可以給我一些線索的一些線索。
import android.app.Activity;
import android.app.ListFragment;
import android.content.PeriodicSync;
import android.os.Bundle;
import android.text.InputFilter.LengthFilter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class NRSessionScheduleFragmentOne extends ListFragment {
String[] dummyVal = new String[] { "hello", "how", "are", "u", "how",
"are", "u", "how", "are" };
ListView parentList;
int addVal;
EditText period;
private NRSessionFragmentHolder parentobj;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.nrtpsessiontopics, container, false);
return v;
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setListAdapter(new MyListAdapter(getActivity()));
parentList = (ListView) getActivity().findViewById(android.R.id.list);
addVal = valueReturn(dummyVal, period, parentList);
}
public class MyListAdapter extends ArrayAdapter {
Activity contextACT;
public MyListAdapter(Activity context) {
super(context, R.layout.nrrow_of_list_lesson, dummyVal);
this.contextACT = context;
}
public View getView(final int position, View convertView,
ViewGroup parent) {
LayoutInflater inflator = contextACT.getLayoutInflater();
final View row = inflator.inflate(R.layout.nrrow_of_list_lesson,
null);
final TextView name = (TextView) row.findViewById(R.id.lessonname);
period = (EditText) row.findViewById(R.id.ssperiodeditText);
final Button increase = (Button) row.findViewById(R.id.ssincrease);
final Button decrease = (Button) row.findViewById(R.id.ssdecrease);
increase.setId(position);
decrease.setId((dummyVal.length) + position);
final Integer currentQuant = Integer.parseInt(period.getText()
.toString());
increase.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
increase.getId();
Log.w("button value", "" + increase.getId());
if (currentQuant != 0) {
period.setText(new Integer(currentQuant + 1).toString());
}
}
});
decrease.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Log.w("button value1", " " + decrease.getId());
decrease.getId();
if (currentQuant != 1) {
period.setText(new Integer(currentQuant - 1).toString());
}
}
});
return (row);
}
}
void setParent(NRSessionFragmentHolder parent) {
this.parentobj = parent;
}
public int valueReturn(String[] dummyVal, EditText period2,
ListView parentList) {
Integer add = 0;
for (int i = 0; i <= dummyVal.length; i++) {
View temp = null;
temp = parentList.getChildAt(i);
while (!(temp == null)) {
add = Integer.parseInt(period2.getText().toString());
}
}
return add;
}
}
鏈接到什麼?你的問題是什麼? – Egor 2011-12-29 08:16:36
它只是我要檢索每個編輯框中存在的所有值 – Vivekanand 2011-12-29 08:21:07
我已添加我的代碼。我正在使用片段方法 – Vivekanand 2011-12-29 08:35:14