我正在尝试在一个喜欢按钮的页面中创建列表视图, 但是当我调试应用程序时,它只显示一个带有名称的黑页。 我有2个java 一个xml到主页面 和一个mainfest.xml
第1页:
package tm.andrioid.com;
import android.app.Activity;
import android.app.Dialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.Button;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.widget.Button;
public class indexActivity extends Activity
{
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
Button bprodukter = (Button) findViewById(R.id.bprodukter);
bprodukter.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(indexActivity.this, produkter.class);
startActivity(i);
}
});
}``
}
第2页java:
tm.andrioid.com;
import android.app.Activity;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
public class produkter extends ListActivity {
String classes[] = { "indexActivity", "Data", "Intim", "Hörlurar", "Prylar",
"Mat", "Sex", "Sju"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(produkter.this,
android.R.layout.simple_list_item_1));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String saker = classes[position];
try{
Class ourClass = Class.forName("tm.android.com." + saker);
Intent ourIntent = new Intent(produkter.this, ourClass);
startActivity(ourIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
main xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tm.andrioid.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="@drawable/tmm"
android:label="@string/app_name" >
<activity
android:name=".splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".indexActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="tm.android.com.INDEXACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".produkter"
android:label="@string/app_name" >
<intent-filter>
<action android:name="tm.android.com.PRODUKTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:0)
替换
setListAdapter(new ArrayAdapter<String>(produkter.this,
android.R.layout.simple_list_item_1));
用这个:
setListAdapter(new ArrayAdapter<String>(produkter.this,
android.R.layout.simple_list_item_1, classes));
让我知道这是否有效。