android listview里面Radiogroup监听事件混乱

public class AdapterTest extends ArrayAdapter {

    private int resourceId;
    List<Test> listTest = new ArrayList<Test>();
    private ViewHolder viewHolder;

    public AdapterTest(Context context, int resource, 

List objects) {
super(context, resource, objects);
resourceId = resource;
listTest = objects;
}

    @Override
    public View getView(final int position, View 

convertView,
ViewGroup parent) {

        viewHolder = new ViewHolder();
        View view = LayoutInflater.from(getContext

()).inflate(resourceId,
null);

        viewHolder.tvTitle = (TextView) view
                .findViewById

(R.id.tv_test_title);
viewHolder.rdoG = (RadioGroup)

view.findViewById(R.id.rdog_test);
viewHolder.radA = (RadioButton)

view.findViewById(R.id.rdo_test_a);
viewHolder.radB = (RadioButton)

view.findViewById(R.id.rdo_test_b);
viewHolder.radC = (RadioButton)

view.findViewById(R.id.rdo_test_c);
viewHolder.radD = (RadioButton)

view.findViewById(R.id.rdo_test_d);
viewHolder.tvAnswer = (TextView) view
.findViewById

(R.id.tv_test_answer);

        viewHolder.tvTitle.setText(String.valueOf

(position + 1) + "、"
+ listTest.get

(position).getTitle());
viewHolder.radA.setText("A、"
+ listTest.get

(position).getQuestionA());
viewHolder.radB.setText("B、"
+ listTest.get

(position).getQuestionB());
viewHolder.radC.setText("C、"
+ listTest.get

(position).getQuestionC());
viewHolder.radD.setText("D、"
+ listTest.get

(position).getQuestionD());
viewHolder.tvAnswer.setText("答案:"
+ listTest.get

(position).getAnswer());

        // viewHolder.rdoG.setTag(position);
        if (listTest.get(position).getChecked

().equals("A")
|| listTest.get

(position).getChecked().equals("B")
|| listTest.get

(position).getChecked().equals("C")
|| listTest.get

(position).getChecked().equals("D")) {

            if (listTest.get(position).getChecked

().equals("A")) {
viewHolder.radA.setChecked

(true);
if (listTest.get

(position).getAnswer()
.equals

(listTest.get(position).getChecked()))

viewHolder.tvAnswer.setTextColor(0xff008000);
else

viewHolder.tvAnswer.setTextColor(0xffdc143c);

viewHolder.tvAnswer.setVisibility(View.VISIBLE);
}
if (listTest.get(position).getChecked

().equals("B")) {
viewHolder.radB.setChecked

(true);
if (listTest.get

(position).getAnswer()
.equals

(listTest.get(position).getChecked()))

viewHolder.tvAnswer.setTextColor(0xff008000);
else

viewHolder.tvAnswer.setTextColor(0xffdc143c);

viewHolder.tvAnswer.setVisibility(View.VISIBLE);
}
if (listTest.get(position).getChecked

().equals("C")) {
viewHolder.radC.setChecked

(true);
if (listTest.get

(position).getAnswer()
.equals

(listTest.get(position).getChecked()))

viewHolder.tvAnswer.setTextColor(0xff008000);
else

viewHolder.tvAnswer.setTextColor(0xffdc143c);

viewHolder.tvAnswer.setVisibility(View.VISIBLE);
}
if (listTest.get(position).getChecked

().equals("D")) {
viewHolder.radD.setChecked

(true);
if (listTest.get

(position).getAnswer()
.equals

(listTest.get(position).getChecked()))

viewHolder.tvAnswer.setTextColor(0xff008000);
else

viewHolder.tvAnswer.setTextColor(0xffdc143c);

viewHolder.tvAnswer.setVisibility(View.VISIBLE);
}
viewHolder.radA.setEnabled(false);
viewHolder.radB.setEnabled(false);
viewHolder.radC.setEnabled(false);
viewHolder.radD.setEnabled(false);
} else {
viewHolder.rdoG.clearCheck();
viewHolder.tvAnswer.setVisibility

(View.GONE);
}
viewHolder.rdoG.setOnCheckedChangeListener(new

OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged

(RadioGroup arg0, int arg1) {
if(viewHolder.rdoG == arg0){
switch (arg1) {
case R.id.rdo_test_a:
listTest.get

(position).setChecked("A");

                        if 

(listTest.get(position).getAnswer()

.equals(listTest.get(position).getChecked()))

viewHolder.tvAnswer.setTextColor(0xff008000);
else

viewHolder.tvAnswer.setTextColor(0xffdc143c);

viewHolder.tvAnswer.setVisibility(View.VISIBLE);

viewHolder.radA.setEnabled(false);

viewHolder.radB.setEnabled(false);

viewHolder.radC.setEnabled(false);

viewHolder.radD.setEnabled(false);
break;

                    case R.id.rdo_test_b:
                        listTest.get

(position).setChecked("B");

                        if 

(listTest.get(position).getAnswer()

.equals(listTest.get(position).getChecked()))

viewHolder.tvAnswer.setTextColor(0xff008000);
else

viewHolder.tvAnswer.setTextColor(0xffdc143c);

viewHolder.tvAnswer.setVisibility(View.VISIBLE);

viewHolder.radA.setEnabled(false);

viewHolder.radB.setEnabled(false);

viewHolder.radC.setEnabled(false);

viewHolder.radD.setEnabled(false);
break;

                    case R.id.rdo_test_c:
                        listTest.get

(position).setChecked("C");

                        if 

(listTest.get(position).getAnswer()

.equals(listTest.get(position).getChecked()))

viewHolder.tvAnswer.setTextColor(0xff008000);
else

viewHolder.tvAnswer.setTextColor(0xffdc143c);

viewHolder.tvAnswer.setVisibility(View.VISIBLE);

viewHolder.radA.setEnabled(false);

viewHolder.radB.setEnabled(false);

viewHolder.radC.setEnabled(false);

viewHolder.radD.setEnabled(false);
break;

                    case R.id.rdo_test_d:
                        listTest.get

(position).setChecked("D");

                        if 

(listTest.get(position).getAnswer()

.equals(listTest.get(position).getChecked()))

viewHolder.tvAnswer.setTextColor(0xff008000);
else

viewHolder.tvAnswer.setTextColor(0xffdc143c);

viewHolder.tvAnswer.setVisibility(View.VISIBLE);

viewHolder.radA.setEnabled(false);

viewHolder.radB.setEnabled(false);

viewHolder.radC.setEnabled(false);

viewHolder.radD.setEnabled(false);
break;

                    default:
                        break;
                    }
                }

            }
        });

        return view;
    }

    class ViewHolder {
        TextView tvTitle;
        RadioGroup rdoG;
        RadioButton radA;
        RadioButton radB;
        RadioButton radC;
        RadioButton radD;
        TextView tvAnswer;

    }
}

}

6个回答

你这问题就是viewholder 的复用问题。
你需要为每个组件设置点击事件。在设置点击事件的时候需要注意:需要保存每一个viewholder。
贴上一段代码:
可以参考一下

 private class AttenOnclickListener implements View.OnClickListener {
        private int position;
        private ViewHolderHouse viewHoder;

        public AttenOnclickListener(int position, ViewHolderHouse viewHoder) {
            this.position = position;
            this.viewHoder = viewHoder;
        }

        @Override
        public void onClick(View v) {
            if (!checkIsLogin()) {
                T.showShort(context, "请先登录!");
            } else {
                startProgressDialog("");
                if ("1".equals(list.get(position).getAttentFlag())) {// 取消关注
                    attentionOrNot(viewHoder, position, "0");
                } else {// 关注
                    attentionOrNot(viewHoder, position, "1");
                }
            }
        }
    }

设置点击事件:

 hHolder.zanLl.setOnClickListener(new ZanOnclickListener(position, hHolder));

这个是一个选择题,选中后答案显示,并且禁用radiobutton图片说明

看着代码乱,先规整了一下代码。没调试,逻辑本身看着没有太大问题,但像ViewHolder这里你是没有起任何优化作用。有了反而成了累赘了。可以看一下ViewHolder怎么用的,这已经满大街都是了,注意一下Item的复用问题就可以了。
有问题就直接把问题问出来。


public class AdapterTest extends ArrayAdapter {
    private int resourceId;
    List<Test> listTest = new ArrayList<Test>();
    private ViewHolder viewHolder;

    public AdapterTest(Context context, int resource, 
List objects) {
super(context, resource, objects);
resourceId = resource;
listTest = objects;
}  
    private void setAnswer(TextView tv,boolean isRight){
            if (isRight)
                tv.setTextColor(0xff008000);
            else
                tv.setTextColor(0xffdc143c);
                tv.setVisibility(View.VISIBLE);
            }
    }

    @Override
    public View getView(final int position, View convertView,ViewGroup parent) {
        viewHolder = new ViewHolder();
        View view = LayoutInflater.from(getContext()).inflate(resourceId,null);
        viewHolder.tvTitle = (TextView) view.findViewById(R.id.tv_test_title);
        viewHolder.rdoG = (RadioGroup)view.findViewById(R.id.rdog_test);
        viewHolder.radA = (RadioButton)view.findViewById(R.id.rdo_test_a);
        viewHolder.radB = (RadioButton)view.findViewById(R.id.rdo_test_b);
        viewHolder.radC = (RadioButton)view.findViewById(R.id.rdo_test_c);
        viewHolder.radD = (RadioButton)view.findViewById(R.id.rdo_test_d);
        viewHolder.tvAnswer = (TextView) view.findViewById(R.id.tv_test_answer);
        viewHolder.tvTitle.setText(String.valueOf(position + 1) + "、"+ listTest.get(position).getTitle());
        viewHolder.radA.setText("A、"+ listTest.get(position).getQuestionA());
        viewHolder.radB.setText("B、"+ listTest.get(position).getQuestionB());
        viewHolder.radC.setText("C、"+ listTest.get(position).getQuestionC());
        viewHolder.radD.setText("D、"+ listTest.get(position).getQuestionD());
        viewHolder.tvAnswer.setText("答案:"+ listTest.get(position).getAnswer());


        viewHolder.rdoG.clearCheck();
        if(listTest.get(position).getChecked()!=null&&listTest.get(position).getChecked().trim().length()>0){
            viewHolder.radA.setEnabled(false);
            viewHolder.radB.setEnabled(false);
            viewHolder.radC.setEnabled(false);
            viewHolder.radD.setEnabled(false);

            this.setAnswer(viewHolder.tvAnswer, listTest.get(position).isRight());
            viewHolder.radA.setChecked(listTest.get(position).getChecked("A".equals(listTest.get(position).getChecked())));
            viewHolder.radB.setChecked(listTest.get(position).getChecked("B".equals(listTest.get(position).getChecked())));
            viewHolder.radC.setChecked(listTest.get(position).getChecked("C".equals(listTest.get(position).getChecked())));
            viewHolder.radD.setChecked(listTest.get(position).getChecked("D".equals(listTest.get(position).getChecked())));
        }else{
            viewHolder.tvAnswer.setVisibility(View.GONE);
        }
        // viewHolder.rdoG.setTag(position);

viewHolder.rdoG.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup arg0, int arg1) {
if(viewHolder.rdoG == arg0){
switch (arg1) {
case R.id.rdo_test_a:
    listTest.get(position).setChecked("A");
    setAnswer(viewHolder.tvAnswer,listTest.get(position).isRight());                    
break;
                    case R.id.rdo_test_b:
                        listTest.get(position).setChecked("B");
break;
                    case R.id.rdo_test_c:
                        listTest.get(position).setChecked("C");
break;
                    case R.id.rdo_test_d:
                        listTest.get(position).setChecked("D");
break;
                    default:
                        break;
                    }

viewHolder.tvAnswer.setVisibility(View.VISIBLE);
viewHolder.radA.setEnabled(false);
viewHolder.radB.setEnabled(false);
viewHolder.radC.setEnabled(false);
viewHolder.radD.setEnabled(false);
                }

            }
        });

        return view;
    }

    class ViewHolder {
        TextView tvTitle;
        RadioGroup rdoG;
        RadioButton radA;
        RadioButton radB;
        RadioButton radC;
        RadioButton radD;
        TextView tvAnswer;

    }
}
}



public class Test {
  private String answer = "";
  private String checked = "";
  private String questionA = "";
  private String questionB = "";
  private String questionC = "";
  private String questionD = "";
  private String title = "";
public String getAnswer() {
    return answer;
}
public void setAnswer(String answer) {
    this.answer = answer;
}
public String getChecked() {
    return checked;
}
public void setChecked(String checked) {
    this.checked = checked;
}
public String getQuestionA() {
    return questionA;
}
public void setQuestionA(String questionA) {
    this.questionA = questionA;
}
public String getQuestionB() {
    return questionB;
}
public void setQuestionB(String questionB) {
    this.questionB = questionB;
}
public String getQuestionC() {
    return questionC;
}
public void setQuestionC(String questionC) {
    this.questionC = questionC;
}
public String getQuestionD() {
    return questionD;
}
public void setQuestionD(String questionD) {
    this.questionD = questionD;
}
public String getTitle() {
    return title;
}
public void setTitle(String title) {
    this.title = title;
}

public boolean isRight(){
    return this.checked!=null&&this.checked.trim().length()>0&&this.checked.equals(this.answer);
}
}
woashizhangsi
泉_哥 赞同
4 年多之前 回复

我点击radiogroup的时候另一个radiogroup会有反应

就是radiogroup的监听事件有问题

保存viewHolder后需要做什么事件处理,能写一些具体的代码吗?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
android listview里面Radiogroup监听事件混乱
public class AdapterTest extends ArrayAdapter nn private int resourceId;n List listTest = new ArrayList();n private ViewHolder viewHolder;nn public AdapterTest(Context context, int resource, nnList objects) n super(context, resource, objects);n resourceId = resource;n listTest = objects;n nn @Overriden public View getView(final int position, View nnconvertView,n ViewGroup parent) nn viewHolder = new ViewHolder();n View view = LayoutInflater.from(getContextnn()).inflate(resourceId,n null);nn viewHolder.tvTitle = (TextView) viewn .findViewByIdnn(R.id.tv_test_title);n viewHolder.rdoG = (RadioGroup) nnview.findViewById(R.id.rdog_test);n viewHolder.radA = (RadioButton) nnview.findViewById(R.id.rdo_test_a);n viewHolder.radB = (RadioButton) nnview.findViewById(R.id.rdo_test_b);n viewHolder.radC = (RadioButton) nnview.findViewById(R.id.rdo_test_c);n viewHolder.radD = (RadioButton) nnview.findViewById(R.id.rdo_test_d);n viewHolder.tvAnswer = (TextView) viewn .findViewByIdnn(R.id.tv_test_answer);nn viewHolder.tvTitle.setText(String.valueOfnn(position + 1) + "、"n + listTest.getnn(position).getTitle());n viewHolder.radA.setText("A、"n + listTest.getnn(position).getQuestionA());n viewHolder.radB.setText("B、"n + listTest.getnn(position).getQuestionB());n viewHolder.radC.setText("C、"n + listTest.getnn(position).getQuestionC());n viewHolder.radD.setText("D、"n + listTest.getnn(position).getQuestionD());n viewHolder.tvAnswer.setText("答案:"n + listTest.getnn(position).getAnswer());nn // viewHolder.rdoG.setTag(position);n if (listTest.get(position).getCheckednn().equals("A")n || listTest.getnn(position).getChecked().equals("B")n || listTest.getnn(position).getChecked().equals("C")n || listTest.getnn(position).getChecked().equals("D")) nn if (listTest.get(position).getCheckednn().equals("A")) n viewHolder.radA.setCheckednn(true);n if (listTest.getnn(position).getAnswer()n .equalsnn(listTest.get(position).getChecked()))n nnviewHolder.tvAnswer.setTextColor(0xff008000);n elsen nnviewHolder.tvAnswer.setTextColor(0xffdc143c);n nnviewHolder.tvAnswer.setVisibility(View.VISIBLE);n n if (listTest.get(position).getCheckednn().equals("B")) n viewHolder.radB.setCheckednn(true);n if (listTest.getnn(position).getAnswer()n .equalsnn(listTest.get(position).getChecked()))n nnviewHolder.tvAnswer.setTextColor(0xff008000);n elsen nnviewHolder.tvAnswer.setTextColor(0xffdc143c);n nnviewHolder.tvAnswer.setVisibility(View.VISIBLE);n n if (listTest.get(position).getCheckednn().equals("C")) n viewHolder.radC.setCheckednn(true);n if (listTest.getnn(position).getAnswer()n .equalsnn(listTest.get(position).getChecked()))n nnviewHolder.tvAnswer.setTextColor(0xff008000);n elsen nnviewHolder.tvAnswer.setTextColor(0xffdc143c);n nnviewHolder.tvAnswer.setVisibility(View.VISIBLE);n n if (listTest.get(position).getCheckednn().equals("D")) n viewHolder.radD.setCheckednn(true);n if (listTest.getnn(position).getAnswer()n .equalsnn(listTest.get(position).getChecked()))n nnviewHolder.tvAnswer.setTextColor(0xff008000);n elsen nnviewHolder.tvAnswer.setTextColor(0xffdc143c);n nnviewHolder.tvAnswer.setVisibility(View.VISIBLE);n n viewHolder.radA.setEnabled(false);n viewHolder.radB.setEnabled(false);n viewHolder.radC.setEnabled(false);n viewHolder.radD.setEnabled(false);n else n viewHolder.rdoG.clearCheck();n viewHolder.tvAnswer.setVisibilitynn(View.GONE);n nviewHolder.rdoG.setOnCheckedChangeListener(new nnOnCheckedChangeListener() n n @Overriden public void onCheckedChangednn(RadioGroup arg0, int arg1) n if(viewHolder.rdoG == arg0)n switch (arg1) n case R.id.rdo_test_a:n listTest.getnn(position).setChecked("A");n n if nn(listTest.get(position).getAnswer()n nn.equals(listTest.get(position).getChecked()))n nnviewHolder.tvAnswer.setTextColor(0xff008000);n elsen nnviewHolder.tvAnswer.setTextColor(0xffdc143c);n nnviewHolder.tvAnswer.setVisibility(View.VISIBLE);n nnviewHolder.radA.setEnabled(false);n nnviewHolder.radB.setEnabled(false);n nnviewHolder.radC.setEnabled(false);n nnviewHolder.radD.setEnabled(false);n break;n n case R.id.rdo_test_b:n listTest.getnn(position).setChecked("B");n n if nn(listTest.get(position).getAnswer()n nn.equals(listTest.get(position).getChecked()))n nnviewHolder.tvAnswer.setTextColor(0xff008000);n elsen nnviewHolder.tvAnswer.setTextColor(0xffdc143c);n nnviewHolder.tvAnswer.setVisibility(View.VISIBLE);n nnviewHolder.radA.setEnabled(false);n nnviewHolder.radB.setEnabled(false);n nnviewHolder.radC.setEnabled(false);n nnviewHolder.radD.setEnabled(false);n break;n n case R.id.rdo_test_c:n listTest.getnn(position).setChecked("C");n n if nn(listTest.get(position).getAnswer()n nn.equals(listTest.get(position).getChecked()))n nnviewHolder.tvAnswer.setTextColor(0xff008000);n elsen nnviewHolder.tvAnswer.setTextColor(0xffdc143c);n nnviewHolder.tvAnswer.setVisibility(View.VISIBLE);n nnviewHolder.radA.setEnabled(false);n nnviewHolder.radB.setEnabled(false);n nnviewHolder.radC.setEnabled(false);n nnviewHolder.radD.setEnabled(false);n break;n n case R.id.rdo_test_d:n listTest.getnn(position).setChecked("D");n n if nn(listTest.get(position).getAnswer()n nn.equals(listTest.get(position).getChecked()))n nnviewHolder.tvAnswer.setTextColor(0xff008000);n elsen nnviewHolder.tvAnswer.setTextColor(0xffdc143c);n nnviewHolder.tvAnswer.setVisibility(View.VISIBLE);n nnviewHolder.radA.setEnabled(false);n nnviewHolder.radB.setEnabled(false);n nnviewHolder.radC.setEnabled(false);n nnviewHolder.radD.setEnabled(false);n break;n n default:n break;n n n n n );n n return view;n nn class ViewHolder n TextView tvTitle;n RadioGroup rdoG;n RadioButton radA;n RadioButton radB;n RadioButton radC;n RadioButton radD;n TextView tvAnswer;nn n nn
android listview中放radiogroup选择混乱
[code=java]rnprivate class MyAdapter extends BaseAdapter rn private Context context = null;rn private ArrayList> list;rn private LayoutInflater inflater = null;rnrnrn public MyAdapter(Context context,ArrayList> list)rn this.context = context;rn this.list = list;rn inflater = LayoutInflater.from(this.context);rn rnrn @Overridern public int getCount() rn return list.size();rn rnrn @Overridern public Object getItem(int position) rn return list.get(position);rn rnrn @Overridern public long getItemId(int position) rn return position;rn rnrnrn @Overridern public View getView(int position, View convertView, ViewGroup parent) rnrn ViewHolder viewHolder = null;rnrn if (convertView == null) rnrn convertView = inflater.inflate(R.layout.questionnairelistitem, null);rn viewHolder = new ViewHolder();rn viewHolder.question = (TextView) convertView.findViewById(R.id.question);rn viewHolder.radioGroup = (RadioGroup) convertView.findViewById(R.id.radioGroup);rn viewHolder.radioyes = (RadioButton) convertView.findViewById(R.id.radioyes);rn viewHolder.radiono = (RadioButton) convertView.findViewById(R.id.radiono);rn convertView.setTag(viewHolder);rnrn else rn viewHolder = (ViewHolder)convertView.getTag();rn rn rn rn viewHolder.radioGroup.setId(position);rn viewHolder.radioGroup.setOnCheckedChangeListener(null);rnrn return convertView;rn rnrnrn private class ViewHolder rn private TextView question;rn private RadioGroup radioGroup;rn private RadioButton radioyes;rn private RadioButton radiono;rnrn rnrn rn[/code]rn请问怎么解决
Android listview Item 监听事件
在一个activity上的listview点击item跳转到下一个activity要注意什么问题,我写的程序设置了itemlistener 但是点击item一点反应没有,有可能出现的问题是什么啊???(程序能运行没有错误,但是就是点击item不能跳转没反应)
RadioGroup控件(接口类监听事件)
前端 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="ma
android ListView项中包含RadioGroup解决混乱选中的问题
ListView项中包含RadioGroup解决混乱选中的问题
弹窗及radiogroup监听事件
1、 不同的弹窗样式,及弹窗中控件的焦点问题 2、 radiogroup 监听事件不同的实现方式
ListView和RadioGroup联合使用,滑动时选项混乱。
在ListView里面使用RadioGroup,在滑动时发现选项有粘连,这是由于复用导致的,我在解决这个问题时查了一些资料,但是问题依然存在,后来发现是我的代码顺序有问题。最终顺序为: 1.先取消监听: viewHolder.radioGroup.setOnCheckedChangeListener(null); 2.清空所有选项: viewHolder.radioGroup.clearCheck...
关于android中listview里面textview显示混乱
哪位大神能帮我解决下面代码中的listview里面textview的显示混乱问题 纠结好久了 谢谢 复制可以直接执行rn源文件:rnpackage com.example.listviewtest;rnrnimport java.util.ArrayList;rnrnimport android.os.Bundle;rnimport android.app.Activity;rnimport android.view.LayoutInflater;rnimport android.view.Menu;rnimport android.view.View;rnimport android.view.View.OnClickListener;rnimport android.view.ViewGroup;rnimport android.widget.BaseAdapter;rnimport android.widget.ImageView;rnimport android.widget.LinearLayout;rnimport android.widget.ListView;rnimport android.widget.NumberPicker;rnimport android.widget.TextView;rnimport android.widget.Toast;rnrnpublic class MainActivity extends Activity rnrnListView list;rnrnArrayList buf = new ArrayList();rnrnLayoutInflater inflater;rn@Overridernprotected void onCreate(Bundle savedInstanceState) rn super.onCreate(savedInstanceState);rn setContentView(R.layout.activity_main);rn list = (ListView)findViewById(R.id.listView1);rn inflater = getLayoutInflater();rn for (int i=0;i<100;i++)rn rn buf.add(String.valueOf(i));rn rn list.setAdapter(adapter);rnrnrnrnBaseAdapter adapter = new BaseAdapter() rnrn @Overridern public View getView(final int position, View convertView, ViewGroup parent) rn // TODO Auto-generated method stubrn ViewHolder viewHolder;rn if (convertView == null)rn rn convertView = inflater.inflate(R.layout.item, null);rn viewHolder = new ViewHolder();rn viewHolder.line = (LinearLayout)convertView.findViewById(R.id.single_item);rn convertView.setTag(viewHolder);rn rn elsern rn viewHolder = (ViewHolder)convertView.getTag();rn rn TextView text = (TextView)viewHolder.line.getChildAt(1);rn text.setText(buf.get(position) + "");rn if (Integer.parseInt(buf.get(position)) % 5 == 0)rn rn text.setTextColor(20);rn viewHolder.line.setClickable(false);rn rnrn viewHolder.line.setOnClickListener(new OnClickListener() rnrn @Overridern public void onClick(View v) rn // TODO Auto-generated method stubrn if (Integer.parseInt(buf.get(position)) % 5 == 0)rn rn return;rn rn Toast.makeText(MainActivity.this, "position==" + position, Toast.LENGTH_SHORT).show();rn rn );rnrn return convertView;rn rnrn @Overridern public long getItemId(int position) rn // TODO Auto-generated method stubrn return 0;rn rnrn @Overridern public Object getItem(int position) rn // TODO Auto-generated method stubrn return null;rn rnrn @Overridern public int getCount() rn // TODO Auto-generated method stubrn return buf.size();rn rnrn class ViewHolder rn rn public LinearLayout line;rn rn;rnrnrn布局文件rn1.activity_main.xmlrnandroid:layout_width="fill_parent"rnandroid:layout_height="fill_parent"rnandroid:orientation="vertical" >rnrnrnrnrn2.item.xmlrnrnrnrnrnrn rnrn rnrn
ListView项中包含RadioGroup解决混乱选中的问题
Android ListView项中包含RadioGroup解决滑动后混乱选中的问题
Android开发:在ListView中使用RadioGroup时出现混乱选中现象
在做类似于投票或者试题的需求时,需要在listview中,一个item展示4个radiobutton,只能选中其中一个的需求,参考了这位博主的实现:android listview radiogroup 不过这篇博客存在两个问题:一是4个radiobutton无法放在两行两列,只能竖直排列、二是滑动多次,radiobutton选中状态会混乱。            1.第一个问题,如何让4个
ListView + CheckBox(或者是RadioGroup等控件)的混乱选中原理
1,常用的写法,只展示Adapter,问题原因就在Adapter中 class Adapter1 extends BaseAdapter{ @Override public int getCount() { return list.size(); } @Override public Objec
求解,listView里面嵌套listView数据显示混乱
我弄了个listView嵌套listView 从服务器上获取数据rn最后显示出来,子项listView 把所有orderproduct里的数据都显示出来了,rnrnJson格式大致是这样rnrn "code": "1",rn "result": [rn rn "id": "10259",rn "createdate": "2014-06-30 21:23",rn "amount": "95.00",rn "score": "0",rn "paytype": "1",rn "statu": "已取消",rn "iscomment": "null",rn "orderproduct": rn "picture": "/attached/image/20140120/1390185473547_3.jpg",rn "productid": "10308",rn "productname": "钢铁是怎样炼成的",rn "productnumber": "1",rn "productprice": "90.0"rn rn ,rn rn "id": "10228",rn "createdate": "2014-03-04 17:50",rn "amount": "1085.00",rn "score": "0",rn "paytype": "1",rn "statu": "已取消",rn "iscomment": "null",rn "orderproduct": [rn rn "picture": "/attached/image/20140304/1393898360387_3.jpg",rn "productid": "10262",rn "productname": "儿童 新生婴儿纯棉防水围脖 围嘴 口水巾 宝宝超可爱绣花围兜围嘴",rn "productnumber": "1",rn "productprice": "12.0"rn ,rn rn "picture": "/attached/image/20140304/1393898360387_3.jpg",rn "productid": "10269",rn "productname": "玛尚N6000 USB笔记本电脑有线鼠标 女生可爱鼠标有线 USB鼠标",rn "productnumber": "1",rn "productprice": "16.0"rn rn ]rn rn ]rnrnrn当我单独读取订单号"id": "10228",这条数据时显示是正常的rn下面的是Json解析的类rnpublic static void orderListRead(String data, List list,rn Context context) rn Info info;rn OrderChildInfo childInfo;rn OrderChildAdapter childAdapter;rn List childList = new ArrayList();rnrn try rn JSONObject jsonobject = new JSONObject(data);rn JSONArray array = jsonobject.getJSONArray("result");rn for (int i = 0; i < array.length(); i++) rn info = new Info();rn JSONObject object = array.getJSONObject(i);rn String id = object.optString("id");// 订单号rn String time = object.optString("createdate");// 时间rn String score = object.optString("score");// 积分rn String status = object.optString("statu");// 状态rn String amount = object.optString("amount");// 合计rn JSONArray jsonArray = object.getJSONArray("orderproduct");rn for (int j = 0; j < jsonArray.length(); j++) rn childInfo = new OrderChildInfo();rn JSONObject objects = jsonArray.getJSONObject(j);rn String name = objects.optString("productname");// 商品rn String number = objects.optString("productnumber");// 数量rn String price = objects.optString("productprice");// 价格rn childInfo.setOrderChildName(name);rn childInfo.setOrderChildCount(number);rn childInfo.setOrderChildPrice(price);rn childList.add(childInfo);rn rn childAdapter = new OrderChildAdapter(context, childList);rn info.setOderCode("订单号" + id);rn info.setOderTime("时间:" + time);rn info.setOderIntegral("积分" + score);rn info.setOderPrice("合计" + amount);rn info.setOderStatus(status);rn info.setChildAdapter(childAdapter);rn list.add(info);rnrn rnrn catch (JSONException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rnrn rnrn下面是adapterrnpublic class OrderListAdapter extends BaseAdapter rn List list;rn LayoutInflater inflater;rn Context context;rnrn public OrderListAdapter(Context context, List list) rn this.context = context;rn this.list = list;rn inflater = LayoutInflater.from(context);rn rnrn @Overridern public int getCount() rn // TODO Auto-generated method stubrn return list == null ? 0 : list.size();rn rnrn @Overridern public Object getItem(int arg0) rn // TODO Auto-generated method stubrn return list.get(arg0);rn rnrn @Overridern public long getItemId(int arg0) rn // TODO Auto-generated method stubrn return 0;rn rnrn @Overridern public View getView(int position, View view, ViewGroup arg2) rn // TODO Auto-generated method stubrn OrderHolder holder;rn if (view == null) rn holder = new OrderHolder();rn view = inflater.inflate(R.layout.order_list_parent_item, null);rn holder.orderCode = (TextView) viewrn .findViewById(R.id.order_item_code);rn holder.orderStatus = (TextView) viewrn .findViewById(R.id.order_item_status);rn holder.orderTime = (TextView) viewrn .findViewById(R.id.order_item_time);rn holder.orderPrice = (TextView) viewrn .findViewById(R.id.order_item_price);rn holder.orderIntegral = (TextView) viewrn .findViewById(R.id.order_item_integral);rn holder.oderChildList = (ListView) viewrn .findViewById(R.id.order_item_list);rn view.setTag(holder);rn else rn holder = (OrderHolder) view.getTag();rn rn Info info = list.get(position);rn holder.orderCode.setText(info.getOderCode());rn holder.orderStatus.setText(info.getOderStatus());rn holder.orderTime.setText(info.getOderTime());rn holder.orderPrice.setText(info.getOderPrice());rn holder.orderIntegral.setText(info.getOderIntegral());rn holder.oderChildList.setAdapter(info.getChildAdapter());rnrn return view;rn rnrn class OrderHolder rn TextView orderCode = null;rn TextView orderStatus = null;rn TextView orderTime = null;rn TextView orderPrice = null;rn TextView orderIntegral = null;rn ListView oderChildList = null;rnrn rn下面是子项listView的adapterrnpublic class OrderChildAdapter extends BaseAdapter rn List list;rn LayoutInflater inflater;rn Context context;rnrn public OrderChildAdapter(Context context, List list) rn this.context = context;rn this.list = list;rn inflater = LayoutInflater.from(context);rn rnrn @Overridern public int getCount() rn // TODO Auto-generated method stubrn return list == null ? 0 : list.size();rn rnrn @Overridern public Object getItem(int arg0) rn // TODO Auto-generated method stubrn return list.get(arg0);rn rnrn @Overridern public long getItemId(int arg0) rn // TODO Auto-generated method stubrn return 0;rn rnrn @Overridern public View getView(int position, View view, ViewGroup arg2) rn // TODO Auto-generated method stubrn OrderChildHolder holder;rn if (view == null) rn holder = new OrderChildHolder();rn view = inflater.inflate(R.layout.order_list_child_item, null);rn holder.orderIcon = (ImageView) viewrn .findViewById(R.id.order_list_child_img);rn holder.orderName = (TextView) viewrn .findViewById(R.id.order_list_child_name);rn holder.orderCount = (TextView) viewrn .findViewById(R.id.order_list_child_count);rn holder.orderPrice = (TextView) viewrn .findViewById(R.id.order_list_child_price);rn view.setTag(holder);rn else rn holder = (OrderChildHolder) view.getTag();rn rn OrderChildInfo info = list.get(position);rn BitmapUtils bitmapUtils = new BitmapUtils(context);rn bitmapUtils.display(holder.orderIcon, info.getOrderChildImg());rn holder.orderName.setText(info.getOrderChildName());rn holder.orderCount.setText(info.getOrderChildCount());rn holder.orderPrice.setText(info.getOrderChildPrice());rn return view;rn rnrn class OrderChildHolder rn ImageView orderIcon = null;rn TextView orderName = null;rn TextView orderCount = null;rn TextView orderPrice = null;rn rnrn
ListView怎么添加RadioGroup
求助,需要实现一个listview ,每一个选项item里有三个radiobutton选项,请问在listview里如何定义和实现
listview点击监听事件失效
今天做项目时发现listview的点击监听事件失效,废了好长时间,后来发现是因为里边有checkbox,对其产生了干扰,可通过在子view里设置checkbox,button等的属性解决此问题,如下: android:clickable="false" android:focusable="false" android:focusableInTouchMode="false"
ListView滑动监听事件
lv_goods.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { switch (scrollS
listView屏幕滑动监听事件
listView.setOnScrollListener(this); @Override public void onItemClick(AdapterView&amp;lt;?&amp;gt; parent, View view, int position, long id) { // TODO Auto-generated method stub String text = listView.g...
Android监听事件
关于Android监听事件的一些认识。Android中的监听事件是通过接口回调来实现的。下面我来说说清Android中是如何设置监听器的。
android监听事件
假如一个按钮,我们要在点击它之后会去执行一些操作,则需要监听器去监听这个按钮,android大概有四种 方式添加监听,以按钮的点击监听为例(前两种方式比较常用到) 1.可以直接让activity实现监听接口 MainActivity implements OnClickListener button.setOnClickListener(this);//给按钮添加监听器 重写onClic
Android的监听事件
案例一 事件监听(三种写法) 1.1 标签上直接绑定监听方法 public void xxx(View view) //第一种 public void xxx(View view) 1.2 创建监听器对象,组件再绑定监听器对象 1.2.1 匿名内部类 1.2.2 使用匿名内部类并定义成全局的属性 第二种: Button viewById = findViewById(R.Id.); vi...
Android ListView弹性效果,处理空ListView, 监听事件
1. ListView用于展示数据列表,没有数据是我们可以设置setEmptyView()设置默认显示 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:lay
ListView解决图片混乱
一个ListView解决图片混乱问题的例子。
ListView和CheckBox的混乱问题
主要是解决我以前的一篇博客仿微信添加群聊界面——addView里listview和checkbox混乱的问题先来上BUG图,我在添加了数据,让listview能滚动起来后就发现了这个问题,大家看图,我只点击了0,滑动后结果10也被点击了,而且再滑回去,被选中的项也会发生变化。
ListView发生混乱和解决办法
1.发生混乱的原因借用别人的图来解释一下:1.如上图第一屏的7条数据,也就是会产生7条数据和7个新的布局,2.当屏幕滑动第一条数据消失,复用机制就会发生了,先把item1放到recycler中,等待屏幕底部数据出现,3当item8出现时,就会复用item1的布局和数据,。也可以这样 public View getView(int position, View convertView, ViewG...
ListView匹配数据混乱
listview数据适配数据混乱
ListView异步加载图片混乱问题
ListView加载多个图片的时候,图片是异步加载的,当item数量多于一屏时,滑动ListView,后面的item在加载图片的时候会混乱。 问题原因是ListView的item复用问题,ListView不会每次都去创建新的item,而是尽量复用之前的item,这就会导致item上图片混乱的问题,也许image对应的position已经改变了,但是它还是去加载以前的bitmap,所以我们要保
解决listView列表混乱
实现功能 1.点击item上的按钮,向后台发送多个请求 2.解析返回的数据 3.及时写入item中 4.解决列表中上展示文本的混乱
解决Android中ListView Radiogroup CheckBox动态绑定数据界面混乱问题
[code=java]package com.wj.sfks.adapter;rnrnimport java.util.ArrayList;rnimport java.util.HashMap;rnimport java.util.List;rnrnimport com.wj.sfks.R;rnimport com.wj.sfks.entity.LDT_TKGL_CHOICEOPTIONEntity;rnimport com.wj.sfks.entity.LDT_TKGL_QUESTIONATTRIBUTEEntity;rnimport android.content.Context;rnimport android.view.LayoutInflater;rnimport android.view.View;rnimport android.view.ViewGroup;rnimport android.widget.ArrayAdapter;rnimport android.widget.CheckBox;rnimport android.widget.CompoundButton;rnimport android.widget.LinearLayout;rnimport android.widget.RadioButton;rnimport android.widget.RadioGroup;rnimport android.widget.TextView;rnrnpublic class MyQuestionAdapter extendsrn ArrayAdapter rn private HashMap lmap;rn private HashMap> cmap;rn private List questions;rn private LayoutInflater iflater;rn private int resourceid;rnrn // private Context context;rnrn public MyQuestionAdapter(Context context, int textViewResourceId,rn List objects) rn super(context, textViewResourceId, objects);rnrn iflater = LayoutInflater.from(context);rn // this.context = context;rn resourceid = textViewResourceId;rn questions = objects;rn lmap = new HashMap();rn cmap = new HashMap>();rn for (int i = 0; i < questions.size(); i++) rn lmap.put(i, -1);rn ArrayList listb = new ArrayList();rn listb.add(false);rn listb.add(false);rn listb.add(false);rn listb.add(false);rn cmap.put(i, listb);rn rn rnrn @Overridern public int getCount() rn // TODO Auto-generated method stubrn return questions.size();rn rnrn @Overridern public LDT_TKGL_QUESTIONATTRIBUTEEntity getItem(int position) rn // TODO Auto-generated method stubrn return questions.get(position);rn rnrn @Overridern public View getView(int position, View convertView, ViewGroup parent) rn ViewHolder vholder = null;rn LDT_TKGL_QUESTIONATTRIBUTEEntity question = questions.get(position);rn ArrayList options = questionrn .getLTCEntitys();rn if (convertView == null) rn convertView = iflater.inflate(resourceid, null);rn vholder = new ViewHolder();rn vholder.item_questionTitle = (TextView) convertViewrn .findViewById(R.id.lbl_QuestionitemTitle);rn vholder.item_questionOptionA = (TextView) convertViewrn .findViewById(R.id.lbl_OptionitemA);rn vholder.item_questionOptionB = (TextView) convertViewrn .findViewById(R.id.lbl_OptionitemB);rn vholder.item_questionOptionC = (TextView) convertViewrn .findViewById(R.id.lbl_OptionitemC);rn vholder.item_questionOptionD = (TextView) convertViewrn .findViewById(R.id.lbl_OptionitemD);rn vholder.item_questionAnswer = (TextView) convertViewrn .findViewById(R.id.lbl_Answer);rn vholder.item_rgOptions = (RadioGroup) convertViewrn .findViewById(R.id.rg_Options);rn vholder.item_layout_OptionCheckeBoxs = (LinearLayout) convertViewrn .findViewById(R.id.layout_CheckeBoxs);rn // if ("单选题".equals(question.getTYPE())) rn vholder.item_rbA = (RadioButton) convertViewrn .findViewById(R.id.rb_OptionA);rn vholder.item_rbB = (RadioButton) convertViewrn .findViewById(R.id.rb_OptionB);rn vholder.item_rbC = (RadioButton) convertViewrn .findViewById(R.id.rb_OptionC);rn vholder.item_rbD = (RadioButton) convertViewrn .findViewById(R.id.rb_OptionD);rn // else rn vholder.item_cbA = (CheckBox) convertViewrn .findViewById(R.id.cb_OptionA);rn vholder.item_cbB = (CheckBox) convertViewrn .findViewById(R.id.cb_OptionB);rn vholder.item_cbC = (CheckBox) convertViewrn .findViewById(R.id.cb_OptionC);rn vholder.item_cbD = (CheckBox) convertViewrn .findViewById(R.id.cb_OptionD);rn // rn else rn vholder = (ViewHolder) convertView.getTag();rn rn vholder.item_questionTitle.setText(question.getZTNUM() + "、"rn + question.getQUESTIONCONTENT());rn vholder.item_questionOptionA.setText("A、"rn + options.get(0).getCHOICEOPTIONCONTENT());rn vholder.item_questionOptionB.setText("B、"rn + options.get(1).getCHOICEOPTIONCONTENT());rn vholder.item_questionOptionC.setText("C、"rn + options.get(2).getCHOICEOPTIONCONTENT());rn vholder.item_questionOptionD.setText("D、"rn + options.get(3).getCHOICEOPTIONCONTENT());rn if ("单选题".equals(question.getTYPE())) rn vholder.item_layout_OptionCheckeBoxs.setVisibility(View.GONE);rn vholder.item_rgOptions.setVisibility(View.VISIBLE);rn vholder.item_rgOptions.setOnCheckedChangeListener(null);rn vholder.item_rgOptions.check(lmap.get(position));rn final int pos = position;rn vholder.item_rgOptionsrn .setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() rn @Overridern public void onCheckedChanged(RadioGroup group,rn int checkedId) rn int id = 0;rn switch (checkedId) rn case R.id.rb_OptionA:rn lmap.put(pos, R.id.rb_OptionA);rn id = 1;rn break;rn case R.id.rb_OptionB:rn lmap.put(pos, R.id.rb_OptionB);rn id = 2;rn break;rn case R.id.rb_OptionC:rn lmap.put(pos, R.id.rb_OptionC);rn id = 3;rn break;rn case R.id.rb_OptionD:rn lmap.put(pos, R.id.rb_OptionD);rn id = 4;rn break;rn rn questions.get(pos).setSelecedId(new int[] id );rn rn );rn else rn vholder.item_layout_OptionCheckeBoxs.setVisibility(View.VISIBLE);rn vholder.item_rgOptions.setVisibility(View.GONE);rn vholder.item_cbA.setOnCheckedChangeListener(null);rn vholder.item_cbB.setOnCheckedChangeListener(null);rn vholder.item_cbC.setOnCheckedChangeListener(null);rn vholder.item_cbD.setOnCheckedChangeListener(null);rn List bools = cmap.get(position);rn if (bools.get(0)) rn vholder.item_cbA.setChecked(true);rn else rn vholder.item_cbA.setChecked(false);rn rn if (bools.get(1)) rn vholder.item_cbB.setChecked(true);rn else rn vholder.item_cbB.setChecked(false);rn rn if (bools.get(2)) rn vholder.item_cbC.setChecked(true);rn else rn vholder.item_cbC.setChecked(false);rn rn if (bools.get(3)) rn vholder.item_cbD.setChecked(true);rn else rn vholder.item_cbD.setSelected(false);rn rn final int pos = position;rnrn // 将4个CheckBox保存到List中,然后循环给CheckBox设置监听事件rn ArrayList cblist = new ArrayList();rn cblist.add(vholder.item_cbA);rn cblist.add(vholder.item_cbB);rn cblist.add(vholder.item_cbC);rn cblist.add(vholder.item_cbD);rn for (int i = 0; i < cblist.size(); i++) rn cblist.get(i).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() rn @Overridern public void onCheckedChanged(CompoundButton buttonView,rn boolean isChecked) rn switch (buttonView.getId()) rn case R.id.cb_OptionA:rn cmap.get(pos).set(0, isChecked);rn break;rn case R.id.cb_OptionB:rn cmap.get(pos).set(1, isChecked);rn break;rn case R.id.cb_OptionC:rn cmap.get(pos).set(2, isChecked);rn break;rn case R.id.cb_OptionD:rn cmap.get(pos).set(3, isChecked);rn break;rn rnrn // 循环CheckBox页面状态数组,将选中项保存进list,然后将保存好的选中项保存到实体对象rn ArrayList ids = new ArrayList();rn List bls = cmap.get(pos);rn for (int j = 0; j < bls.size(); j++) rn if (bls.get(j)) rn ids.add(j + 1);rn rn rn // 将List转换为int数组rn int[] seids = new int[ids.size()];rn for (int n = 0; n < ids.size(); n++) rn seids[n] = Integer.parseInt(ids.get(n).toString());rn rn // 将选中的CheckBox保存进实体对象rn questions.get(pos).setSelecedId(seids);rn rn );rn rn rn rn convertView.setTag(vholder);rn return convertView;rn rnrn class ViewHolder rn // 问题内容rn TextView item_questionTitle;rnrn // 选项内容rn TextView item_questionOptionA;rn TextView item_questionOptionB;rn TextView item_questionOptionC;rn TextView item_questionOptionD;rnrn // 单选组rn RadioGroup item_rgOptions;rn RadioButton item_rbA;rn RadioButton item_rbB;rn RadioButton item_rbC;rn RadioButton item_rbD;rnrn // 多选、不定选组rn LinearLayout item_layout_OptionCheckeBoxs;rn CheckBox item_cbA;rn CheckBox item_cbB;rn CheckBox item_cbC;rn CheckBox item_cbD;rnrn // 答案rn TextView item_questionAnswer;rnrn rnrnrn[/code]rnrn好好看代码哇,折腾了三天才搞出来
C++里面混乱的字符串操作
小弟刚开始用C++做项目,发现c++里面的字符串转换很是麻烦,字符编码搞得我头都大了,做项目的大部分时间都浪费到了字符串转换上面,从char* CString LPCTSTR LPCTWSTR等多个类型的字符类型,大家在做项目的时候是不是都约定某一种编码,省的来回的转换,还有在这方面有没有什么技巧的,望分享。
android listview 里面使用checkbox
这是我自己写的android listview里面使用checkbox的demo
ListView Item点击监听事件失效
最近接着前任的项目继续写,改了ListView 适配器的布局,后来发现OnItemClickListener监听失效了,之前就没有问题,纠结了很久,应该是button拦截了Item的点击事件,后来发现直接把Item里面的布局的Button改成TextView就好了,写一笔在此,不喜勿喷!
vs2005 里面没有RadioGroup吗?
找了半天也没找到
listview中的图标加载混乱
第一次进入页面时,图标都是显示在正确的位置,但是当滑动时就出现问题了——加载混乱,不该出现的位置也出现了。。下面是adapter的getView方法代码,listview常见的解决办法也使用了,怎么还会有问题呢?[img=http://img.my.csdn.net/uploads/201212/05/1354674341_2400.jpg][/img][code=java] @Overridern public View getView(final int position, View convertView,rn ViewGroup parent) rn View view = null;rn ViewHolder holder = null;rn if (convertView != null) rn view = convertView;rn holder = (ViewHolder) view.getTag();rn else rn view = mInflater.inflate(R.layout.linedetail_item, null);rn holder = new ViewHolder();rn holder.bus_icon = (ImageView) view.findViewById(R.id.bus_icon);rn holder.bus_LineName = (TextView) viewrn .findViewById(R.id.et_staticonname);rn holder.bus_num = (TextView) view.findViewById(R.id.et_busnum);rn holder.bus_serial = (TextView) viewrn .findViewById(R.id.et_serial);rn view.setTag(holder);rn rn // 绑定数据rn if (istop) rn if (map.containsKey(position + 1 + "")) rn String str = map.get(position + 1 + "");rn int num = Integer.parseInt(str);rn if (num == 1) rn holder.bus_icon.setImageResource(R.drawable.bus_blue);rn else rn holder.bus_num.setText(str);rn holder.bus_icon.setImageResource(R.drawable.bus_blue);rn rn rn holder.bus_LineName.setText(list.get(position));rn holder.bus_LineName.setOnClickListener(new OnClickListener() rn @Overridern public void onClick(View v) rn goto_stationName = list.get(position);rn Log.i("i", "目的地站点名称是::" + goto_stationName);rn showDialogSetUp();rn rn );rn else rn if (down_map.containsKey(position + 1 + "")) rn String str = down_map.get(position + 1 + "");rn int num = Integer.parseInt(str);rn if (num == 1) rn holder.bus_icon.setImageResource(R.drawable.bus_blue);rn else rn holder.bus_num.setText(str);rn holder.bus_icon.setImageResource(R.drawable.bus_blue);rn rn rn holder.bus_LineName.setText(down_list.get(position));rn holder.bus_LineName.setOnClickListener(new OnClickListener() rn @Overridern public void onClick(View v) rn goto_stationName = down_list.get(position);rn Log.i("i", "目的地站点名称是::" + goto_stationName);rn showDialogSetUp();rn rn );rn rn holder.bus_serial.setText(position + 1 + ".");// 序号rn // 可以根据istop 标记为来显示车辆的图标 ,map的key是站点序号rn return view;rn [/code]
关于ListView 下标混乱的处理
一般如果在List的adapter里面的getView()方法里面不要单独加单方面的判断,比如if 为条件一定要带上else。这样就不会出现删除一个Item其他的Item的排序就乱了
RadioGroup,Android的单选框。
在安卓上,实现单选框。 先看一下需求:在用户注册页面需要填性别项,大家知道性别不是男的便是女的。(这里不考虑其它情况)这时候单选框就派上用场了,先看布局文件。<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" andro
android 流式布局 和 RadioGroup自动换行
android 流式布局 ,其实这个有点烂大街,之所以说下,主要是因为RadioGroup这个东西,缺少的就是自适应的能力,不能换行搞的很烦,其实核心的代码也就是流式布局的onMeasure和 onLayout 。测量和分布。 代码: github github地址 简单说下RadioGroup的自动换行 看一下核心的代码 onMeasure int widthSize = Measur...
Android 学习(6)RadioGroup
自学 Android 做的第六个 Android 程序,使用了 RadioGroup
Android Radiogroup 布局问题
现有5个单选按钮,水平放置的话一排有点拥挤,我打算分两排显示,第一排三个,第二排两个,于是我在RadioGroup中加入了两个先行布局,但是加好后发现这几个单选按钮不是一组了,每个都可以被选中,请问有什么解决办法吗,或者能采用什么方法让单选按钮自动换行吗?
轻松解决listView数据混乱
思路:1.定义成员变量lmap     2.判断convertView==null添加到lmap不为空直接从lmap中取出convertView      MyOrderAdapter .java public class MyOrderAdapter extends BaseAdapter { private Context ac; private ArrayList data;
Android自定义Radiogroup?
[img=https://img-bbs.csdn.net/upload/201403/30/1396158617_926711.png][/img]rn是否可以实现如上结果,RaddioButton没有什么难度,关键后边归类的那个:rn[img=https://img-bbs.csdn.net/upload/201403/30/1396158707_582831.png][/img]rn如何实现呢?
Android Studio RadioGroup
![图片说明](https://img-ask.csdn.net/upload/201608/18/1471508791_802755.png)
相关热词 c# 标准差 计算 c#siki第五季 c#入门推荐书 c# 解码海康数据流 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池