【问题标题】:Android Adapter View Read Onclick ItemAndroid 适配器视图读取 Onclick 项
【发布时间】:2013-09-13 06:19:56
【问题描述】:

我已经编写了一个代码,用于在 android 适配器视图上读取 onclick 项,

String s = (lv.getItemAtPosition(position).toString());

我正在使用

i.putExtra("myvalues", s);

在我的第二课页面上显示如下输出:

{description=关于选中的描述,title=选中的标题}

我只想知道如何分别显示描述和标题。

例如:

选定的标题(显示在一个 TextView 上) 关于选中的描述(显示在另一个 TextView 上)

--- 一级 ------------

public void onItemClick(AdapterView parent, View view, int 位置,长 id) {

        String s = (lv.getItemAtPosition(position).toString());

        Intent i=new Intent(PageOne.this, PageTwo.class);
        i.putExtra("name", s);
        startActivity(i);



    }

-----------------第二页------------------

我抓住了这个价值:

TextView Textv = (TextView) findViewById(R.id.singleidview);
Intent iin = getIntent();
Bundle b = iin.getExtras();
if (b != null) {
    String j = (String) b.get("name");
    Textv.setText(j);
}

【问题讨论】:

  • 请多解释一下
  • 向我们展示您的适配器。
  • 所以使用自定义适配器和你的每行自定义布局(如果你想在不同的文本视图中设置值,它们需要有 2 个文本视图)
  • @MarkoNiciforovic 那么,如何为两个文本视图拆分 {description=description about selected, title=selected title} 值,有没有比 String parts[] = yourstring.split(", ");

标签: android


【解决方案1】:

我认为你在谈论这个

       String parts[] = yourstring.split(",");

      parts[0] gives first string as description set this in first textview
       parts[1] gives your title set this in second textview

【讨论】:

  • 感谢您的帮助,但如果我们使用 ","parts[0] = {description=description about selected .. 进行拆分,这意味着它应该再次拆分以达到该输出
  • 在下一步使用替换而不是拆分意味着使用replace("description=","");这意味着用空白字符串替换字符串
猜你喜欢
  • 1970-01-01
  • 2013-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-27
  • 1970-01-01
  • 1970-01-01
  • 2015-10-24
相关资源
最近更新 更多