リストに情報をこすり落とし、私はこのウェブサイトからjsoup使用してデータを解析されてきました移入画面は、私はカスタムリストにWebサイトから情報を掻き取り、画面を移入したい
public class ScoresActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.scoresactivity);
setListAdapter(new MyAdapter(this, android.R.layout.simple_list_item_1, R.id.textViewhometeam,
getResources().getStringArray(R.array.pls)));
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
//int pos = lv.getSelectedItemPosition();
//if(pos == 0){
//Intent intent = new Intent(Legends.this, l1.class);
//startActivity(intent);
//}
}
});
}
public class MyAdapter extends ArrayAdapter<String>{
public MyAdapter(Context context, int resource, int textViewResourceId,
String[] strings) {
super(context, textViewResourceId, strings);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.list_item3, parent, false);
//String[] items = getResources().getStringArray(R.array.legends);
TextView tv1 = (TextView) row.findViewById(R.id.textViewhometeam);
TextView tv2 = (TextView) row.findViewById(R.id.textViewfinalscore);
TextView tv3 = (TextView) row.findViewById(R.id.textViewawayteam);
Document doc;
try {
doc = (Document) Jsoup.connect("http://www.soccerway.com/teams/saudi-arabia/al-nasr-riyadh/matches/").get();
Elements team_a = ((Element) doc).select("td.team-a");
for (Element e : team_a) {
CharSequence ta = e.text();
tv1.setText(ta);
//System.out.println("team a is: " + ta);
}
Elements team_b = ((Element) doc).select("td.team-b");
for (Element e : team_b) {
CharSequence tb = e.text();
tv3.setText(tb);
//System.out.println("team b is: " + tb);
}
Elements result = ((Element) doc).select("td.score");
for (Element e : result) {
CharSequence re = e.text();
tv2.setText(re);
//System.out.println("score is: " + re);
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return row;
}
}
}
scoresactivity.xmlは、単にリストビュー0123ですが、私はそれがここで実行時例外が発生したコードとエラートレースしている私のアプリを起動カントlist_item3.xmlは私のカスタムリストです。ホームチーム、アウェーチーム、スコアの3つのテキストビューを含んでいます。ここ
は誤りである:ここでは
11-09 02:33:24.379: ERROR/AndroidRuntime(325): FATAL EXCEPTION: main
11-09 02:33:24.379: ERROR/AndroidRuntime(325): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nassr.alnassrfc/com.nassr.alnassrfc.Main}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at android.os.Looper.loop(Looper.java:123)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at java.lang.reflect.Method.invoke(Method.java:521)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at dalvik.system.NativeStart.main(Native Method)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): Caused by: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at android.app.TabActivity.onContentChanged(TabActivity.java:105)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at android.app.Activity.setContentView(Activity.java:1647)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at com.nassr.alnassrfc.Main.onCreate(Main.java:19)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-09 02:33:24.379: ERROR/AndroidRuntime(325): ... 11 more
11-09 02:33:24.399: WARN/ActivityManager(59): Force finishing activity com.nassr.alnassrfc/.Main
11-09 02:33:24.899: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{45073020 com.nassr.alnassrfc/.Main}
11-09 02:33:26.921: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: [email protected]
は私のメインクラスがTabActivityを拡張し、TabHost
public class Main extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custome_title);
Resources res = getResources();
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
TabHost.TabSpec spec;
Intent intent; // Reusable Intent for each tab
tabHost.getTabWidget();
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, ClubActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("club").setIndicator("",
res.getDrawable(R.drawable.ic_tab_alnassr))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, ScoresActivity.class);
spec = tabHost.newTabSpec("scores").setIndicator("",
res.getDrawable(R.drawable.ic_tab_alnassr1))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, TableActivity.class);
spec = tabHost.newTabSpec("table").setIndicator("",
res.getDrawable(R.drawable.ic_tab_alnassr2))
.setContent(intent);
tabHost.addTab(spec);
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, MessageList.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("News").setIndicator("",
res.getDrawable(android.R.drawable.star_on))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, YoutubeActivity.class);
spec = tabHost.newTabSpec("youtube").setIndicator("",
res.getDrawable(R.drawable.ic_tab_alnassr3))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
} おかげでみんなを使用しています。
こんにちはsgarman、scoresactivityに関連するすべてのコードを削除すると(そしてそれはタブです)、上記のコードがscoresactivityで使用されると、プログラム全体が実行時に実行されませんエラー。だから基本的にはエラーが上のコードにあります。主な活動についてのあなたの質問についてはtabhostを拡張しません、それはtabactivityを拡張する...これは助けて欲しい:) – Roy87
あなたが必要な拡張TabActivity参照:http://developer.android.com/resources/tutorials/views/hello-tabwidget.htmlタブでの使用。あなたのタブアビリティとレイアウトを見ずに、問題が何であるかを知ることは難しいです。私はあなたがこの活動をどのように立ち上げているのかはまだ分かりません。 –
sgarman
私の主な活動を見るには上記をチェックしてください – Roy87