【发布时间】:2015-02-09 09:11:35
【问题描述】:
我从ArrayList<ArrayList<String>> 中设置了一个ListView,称为data of data,看起来像这样
data = {{"cat1","cat2","cat3","cat4"},
{"dog1","dog2","dog3"},
{"lion1"},
{"monkey1","monkey2"}};
我是这样设置的:
public static final String[] weekdayStringArray = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ArrayList<String> stringArrayList = data.get(position);
String dayString = weekdayStringArray[dayNumber];
switch(stringArrayList.size()){
case 4:
convertView = mLayoutInflater.inflate(R.layout.four_meal_item_view, parent, false);
TextView mealOne_Four = (TextView) convertView.findViewById(R.id.firstMealTextView);
TextView mealTwo_Four = (TextView) convertView.findViewById(R.id.secondMealTextView);
TextView mealThree_Four = (TextView) convertView.findViewById(R.id.thirdMealTextView);
TextView mealFour_Four = (TextView) convertView.findViewById(R.id.fourthMealTextView);
TextView dayText_Four = (TextView) convertView.findViewById(R.id.dayTextView);
dayText_Four.setText(dayString);
mealOne_Four.setText(stringArrayList.get(0).substring(0,1).toUpperCase() + stringArrayList.get(0).substring(1).toLowerCase());
mealTwo_Four.setText(stringArrayList.get(1).substring(0,1).toUpperCase() + stringArrayList.get(1).substring(1).toLowerCase());
mealThree_Four.setText(stringArrayList.get(2).substring(0,1).toUpperCase() + stringArrayList.get(2).substring(1).toLowerCase());
mealFour_Four.setText(stringArrayList.get(3).substring(0,1).toUpperCase() + stringArrayList.get(3).substring(1).toLowerCase());
break;
case 3:
convertView = mLayoutInflater.inflate(R.layout.three_meal_item_view, parent, false);
TextView mealOne_Three = (TextView) convertView.findViewById(R.id.firstMealTextView_Three);
TextView mealTwo_Three = (TextView) convertView.findViewById(R.id.secondMealTextView_Three);
TextView mealThree_Three = (TextView) convertView.findViewById(R.id.thirdMealTextView_Three);
TextView dayText_Three = (TextView) convertView.findViewById(R.id.dayTextView_Three);
dayText_Three.setText(dayString);
mealOne_Three.setText(stringArrayList.get(0).substring(0,1).toUpperCase() + stringArrayList.get(0).substring(1).toLowerCase());
mealTwo_Three.setText(stringArrayList.get(1).substring(0,1).toUpperCase() + stringArrayList.get(1).substring(1).toLowerCase());
mealThree_Three.setText(stringArrayList.get(2).substring(0,1).toUpperCase() + stringArrayList.get(2).substring(1).toLowerCase());
break;
case 2:
convertView = mLayoutInflater.inflate(R.layout.two_meal_item_view, parent, false);
TextView mealOne_Two = (TextView) convertView.findViewById(R.id.firstMealTextView_Two);
TextView mealTwo_Two = (TextView) convertView.findViewById(R.id.secondMealTextView_Two);
TextView dayText_Two = (TextView) convertView.findViewById(R.id.dayTextView_Two);
dayText_Two.setText(dayString);
mealOne_Two.setText(stringArrayList.get(0).substring(0,1).toUpperCase() + stringArrayList.get(0).substring(1).toLowerCase());
mealTwo_Two.setText(stringArrayList.get(1).substring(0,1).toUpperCase() + stringArrayList.get(1).substring(1).toLowerCase());
break;
case 1:
convertView = mLayoutInflater.inflate(R.layout.one_meal_item_view, parent, false);
TextView mealOne_One = (TextView) convertView.findViewById(R.id.firstMealTextView_One);
TextView dayText_One = (TextView) convertView.findViewById(R.id.dayTextView_One);
dayText_One.setText(dayString);
mealOne_One.setText(stringArrayList.get(0).substring(0,1).toUpperCase() + stringArrayList.get(0).substring(1).toLowerCase());
break;
case 0:
convertView = mLayoutInflater.inflate(R.layout.zero_meal_item_view, parent, false);
TextView dayText_Zero = (TextView) convertView.findViewById(R.id.dayTextView_Zero);
dayText_Zero.setText(dayString + "(Closed)");
break;
}
return convertView;
现在我想添加一个onClickListener,这样我就可以连续点击一个TextView。当单击此TextView 时,我将移动到一个新的Activity,传递单击的TextView 的文本以及与单击的TextView 位于同一行的dayTextView 的文本。
现在我不想为每个TextView 设置一堆onClickListners 那么对于我的行中的所有TextViews 执行此操作的有效方法是什么? ListView?
【问题讨论】:
标签: android listview textview onclicklistener