yid从tabhost内的活动多数民众赞成在tabhost内部的

yid从tabhost内的活动多数民众赞成在tabhost内部的

本文介绍了我怎么findviewbyid从tabhost内的活动多数民众赞成在tabhost内部的看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索看法,但它一直返回null,我怎么找到它?

 公共类TripDailyItinerary延伸活动{
ViewGroup中布局;
视图V;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
// TODO自动生成方法存根
super.onCreate(savedInstanceState);
的setContentView(R.layout.html_content);
TextView的内容=(的TextView)findViewById(R.id.htmlContent);
布局=(ViewGroup中)findViewById(R.layout.trip_content);
V =(查看)layout.findViewById(R.id.bg); //错误所在
JSONObject的保留;
。INT resNumber =((MyApp的)this.getApplication())getResNum();
串dailyitinerary =;尝试{
预订=((MyApp的) this.getApplication()).getJSON().getJSONObject(\"response\").getJSONArray(\"reservations\").getJSONObject(resNumber);
dailyitinerary = reservation.getString(dailyitinerary);
}赶上(JSONException E){
// TODO自动生成catch块
e.printStackTrace();
}
content.setText(Html.fromHtml(dailyitinerary));
}}

我一直在V =(视图)得到一个NullPointerException异常....等。


解决方案

 布局=(ViewGroup中)findViewById(R.layout.trip_content);
V =(查看)layout.findViewById(R.id.bg); //错误所在

下面取代上述的两行

  LayoutInflater吹气=(LayoutInflater)的getContext()getSystemService(Context.LAYOUT_INFLATER_SERVICE)。
查看查看= inflater.inflate(R.layout.R.layout.trip_content,NULL);
TextView的名字=(TextView中)view.findViewById(R.id.bg);

TextView的也可以在控制或者ImageView的和任何其他替代。

I'm trying to retrieve a view but it keeps returning null, how do I find it?

public class TripDailyItinerary extends Activity {
ViewGroup layout;
View v;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.html_content);
TextView content = (TextView) findViewById(R.id.htmlContent);
layout = (ViewGroup) findViewById(R.layout.trip_content);
v = (View) layout.findViewById(R.id.bg); //where the error is


JSONObject reservation;
int resNumber = ((MyApp) this.getApplication()).getResNum();
String dailyitinerary = "";

try {
reservation = ((MyApp) this.getApplication()).getJSON().getJSONObject("response").getJSONArray("reservations").getJSONObject(resNumber);
dailyitinerary = reservation.getString("dailyitinerary");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
content.setText(Html.fromHtml(dailyitinerary));
}

}

I keep getting a NullPointerException at v = (view) .... etc.

解决方案
layout = (ViewGroup) findViewById(R.layout.trip_content);
v = (View) layout.findViewById(R.id.bg); //where the error is

replace the above two lines with below

LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view view = inflater.inflate(R.layout.R.layout.trip_content,null);
TextView name = (TextView) view.findViewById(R.id.bg);

also TextView can be replaced with your control either ImageView and any other.

这篇关于我怎么findviewbyid从tabhost内的活动多数民众赞成在tabhost内部的看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:42