【发布时间】:2014-12-14 17:22:32
【问题描述】:
我有一个多行的 ListView,每行都有多个 textView,现在为每行设置一个 onClickListener 既不方便又糟糕。
我如何为所有 TextView 设置一个 onClickListener,因为每个都将执行相同的意图(它会进入相同的下一个活动)。但是每个 on 都将其文本作为该意图中的额外内容传递。
那么我该如何为 TextViews 设置这个,点击 Listineres 呢?
感谢您的帮助。
编辑
好的,抱歉,我可能没有为我设置的 ListView 完全解释这一点。
我有 5 种不同类型的细胞。一个有 4 个 textViews,一个有 3 个 textViews,以此类推到 0。
在我的 getView 中,我有这样的设置
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;
对于单击 textView 不,我想转到一个新活动并传递被单击的 TextView 的文本和该行的 dayTextView 的文本。
我希望这能更好地解释它。
【问题讨论】:
标签: android textview onclicklistener