【问题标题】:More info on menu selection Glass有关菜单选择的更多信息 Glass
【发布时间】:2014-11-20 17:52:43
【问题描述】:

我有一个 CardScrollView,其中包含列表中的多个项目,我想进一步扩展所选项目并提供更多信息,例如:

  1. 用户刷卡
  2. 用户点击侧面(或使用语音)
  3. 用户从菜单中选择“更多信息”
  4. (在这部分不确定)使用该卡中的详细信息启动新活动(这些详细信息存储在对象中)

这是我的代码,它在文本视图部分失败(此代码在 mainactivity.java 中

case R.id.settings_3: //More Info
           Log.v("Option_selected", "More Info " + jCardScrollView.getSelectedItemPosition());
           List<Stuff> stuff = currJobList.getList();
           String textDesc = stuff.get(jCardScrollView.getSelectedItemPosition()).getStuffDesc();
           TextView view = (TextView) findViewById(R.id.init_text);
           view.setText(textDesc); // add the description text into new activity

           // launch the activity
           Intent infoIntent = new Intent(this,MoreInfoActivity.class);
           startActivity(infoIntent);

【问题讨论】:

    标签: android google-glass


    【解决方案1】:

    您应该在 onCreate 非打开之前将描述 textView 插入到新活动中。您可以使用

    通过活动发送 textDesc 字符串
    infoIntent.putExtra("textDesc", textDesc);
    

    并在新的活动中检索它

    Bundle extras = getIntent().getExtras();
    String desc=(String) extras.getString("textDesc");
    

    【讨论】:

    • 然后我会开始活动还是将 desc 传递给某些东西?
    • 是的,使用 startActivity 的目的是在其中添加额外的内容。然后使用我编写的代码在 onCreate(新活动的)中检索。
    • 好的,尝试此操作后,我收到以下玻璃错误gist.github.com/char-tay/ae443b2d47cb15a6bc68
    • 看来你有一个空指针。仅阅读异常我无法帮助您,您可以发布代码吗?
    • 我明白你的意思了,看看下面的答案,非常感谢你的帮助
    【解决方案2】:

    感谢您的帮助@Cloud57 我试图在调用 oncreate 函数之前更改文本,这是调用的第二个活动

     protected void onCreate(Bundle savedInstanceState) {
        //call onCreate first
        super.onCreate(savedInstanceState);
        //set the content view before setting any text
        setContentView(R.layout.more_info);
    
        textV = (TextView) findViewById(R.id.init_text);
        Bundle extras = getIntent().getExtras();
    
        if(extras!=null){
            String j = (String) extras.get("textDesc");
            textV.setText(j);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-17
      • 1970-01-01
      • 2017-04-24
      相关资源
      最近更新 更多