2014-02-15 18 views
0

我正在爲我的應用程序創建搜索,我需要做的最後一件事情之一是在用戶單擊搜索建議時「提取」數據。我設置了Intent.ACTION_VIEW並通過intent.getData()得到了數據;在我的搜索活動。但是,我現在應該怎麼做才能查看數據中的「打包」TextView和ImageView等對象?我對此沒有太大的經驗,所以你能給我一些建議嗎?如何在Intent.ACTION_VIEW之後顯示數據?

非常感謝

我的代碼示例:

if (Intent.ACTION_VIEW.equals(intent.getAction())) { 
      setContentView(R.layout.activity_more); 
      intent.getData(); 
      final ProgressBar progress = (ProgressBar) findViewById(R.id.more_progress); 
      progress.setVisibility(View.VISIBLE); 
      TextView about = (TextView)findViewById(R.id.more_about); 
      TextView animal = (TextView)findViewById(R.id.more_animal); 
      final ImageView imgUrl = (ImageView)findViewById(R.id.more_imgUrl); 

//now do i need to set Text etc., but how? 

} 

回答

0

只需將它們添加到任何佈局在您的活動,他們將在它顯示出來。

How to Programmatically Add Views to Views

對於expample,你有id爲mylayout一個LinearLayout中。

LinearLayout layout = (LinearLayout) findViewById("mylayout"); 
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
layout.addView(myView, lp); 

或者,你可以配置的視圖,並使用從他們唯一的數據 - 從ImageView的TextView的,從文字,繪製等

相關問題