2012-04-05 3 views
0

ビューを取得しようとしていますが、nullを返すことはありますが、どのように見つけられますか?タブホスト内のアクティビティからタブホスト内のビューを見つける方法はありますか?

IがのTextViewを交換することができ、また以下

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); 

と上記2つの行を置き換える

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

+0

あなたのコードを共有する.. –

+0

あなたのレイアウトでviewIdを正しく確認する必要があります。実際の質問よりも大きいので、コードを分けて質問の説明を短くしてください。 – Sankalp

+0

投稿コード... –

答えて

0
等.... V =(ビュー)でNullPointerExceptionが取得維持
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)); 
} 

} 

あなたのコントロールでImageViewと他のいずれか。

0

使用この:

ViewGroup parent = (ViewGroup)findViewById(R.id.trip_layout); 
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View myView = inflater.inflate(R.layout.trip_content,parent); 

あなたはnullが警告を行っているためのTextView

TextView content = (TextView)myView.findViewById(R.id.htmlContent);

を追加したい場合は...

R.id.trip_layoutは、あなたのXMLレイアウトの親のレイアウトです。

関連する問題