我有一個問題,我的代碼iv一直試圖解決這個錯誤,但仍然沒有運氣。我想一個新的活動啓動時,在列表視圖中的項目被點擊我找了一段時間發現這個代碼listview點擊多個活動
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
switch(position)
{
case 0: Intent newActivity = new Intent(this, superleague.class);
startActivity(newActivity);
break;
case 1: Intent newActivity = new Intent(this, youtube.class);
startActivity(newActivity);
break;
case 2: Intent newActivity = new Intent(this, olympiakos.class);
startActivity(newActivity);
break;
case 3: Intent newActivity = new Intent(this, karaiskaki.class);
startActivity(newActivity);
break;
case 4: Intent newActivity = new Intent(this, reservetickets.class);
startActivity(newActivity);
break;
}
}
現在我把這個在我的項目,它是哪裏的問題,但因爲我新的這需要一些時間來解決小事希望你能幫助?
package com.mybasicapp;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Toast;
public class menu extends ListActivity implements onListItemClickListner{
ImageButton ImagebuttonOpenDialog;
String KEY_TEXTPSS = "TEXTPSS";
static final int CUSTOM_DIALOG_ID = 0;
ListView dialog_ListView;
String[] listContent = {
"FORD", "BMW", "AUDI", "JAGUAR",
"MERCEDES", "RENAULT", "ROVER", "SAAB", "BENTLEY",
"VOLVO", "VAUXHALL", "SEAT"};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnListItemClickListener(new OnListItemClickListener() {
public void onListItemClick(AdapterView<?> parent, View view,
int position, long id) {
switch(position)
{
case 0: Intent newActivity = new Intent(this,
Pickmodel.class);
startActivity(newActivity);
break;
case 1: Intent newActivity = new Intent(this,
Pickmodel.class);
startActivity(newActivity);
break;
case 2: Intent newActivity = new Intent(this,
Pickmodel.class);
startActivity(newActivity);
break;
case 3: Intent newActivity = new Intent(this,
Pickmodel.class);
startActivity(newActivity);
break;
case 4: Intent newActivity = new Intent(this,
Pickmodel.class);
startActivity(newActivity);
break;
}
}
ImagebuttonOpenDialog = (ImageButton)findViewById(R.id.imgbtn1);
ImagebuttonOpenDialog.setOnClickListener(new Button.OnClickListener(){
public void onClick(View arg0) {
showDialog(CUSTOM_DIALOG_ID);
}});
}
@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch(id) {
case CUSTOM_DIALOG_ID:
dialog = new Dialog(menu.this);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Custom Dialog");
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.setOnCancelListener(new OnCancelListener(){
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
Toast.makeText(menu.this,
"OnCancelListener",
Toast.LENGTH_LONG).show();
}});
dialog.setOnDismissListener(new OnDismissListener(){
public void onDismiss(DialogInterface dialog) {
// TODO Auto-generated method stub
Toast.makeText(menu.this,
"OnDismissListener",
Toast.LENGTH_LONG).show();
}});
//Prepare ListView in dialog
dialog_ListView = (ListView)dialog.findViewById(R.id.dialoglist);
ArrayAdapter<String> adapter
= new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, listContent);
dialog_ListView.setAdapter(adapter);
dialog_ListView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
Toast.makeText(menu.this,
parent.getItemAtPosition(position).toString() + " clicked",
Toast.LENGTH_LONG).show();
dismissDialog(CUSTOM_DIALOG_ID);
}});
break;
}
return dialog;
}
@Override
protected void onPrepareDialog(int id, Dialog dialog, Bundle bundle) {
// TODO Auto-generated method stub
super.onPrepareDialog(id, dialog, bundle);
switch(id) {
case CUSTOM_DIALOG_ID:
//
break;
}
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
請讓我知道如果我失去了一些東西也感謝 P.S我不能運行這個項目,所以我不能打印日誌CAT
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/customdialog"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="20dp"
android:minWidth="300dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/popcar" />
<ListView
android:id="@+id/dialoglist"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/kj" />
</LinearLayout>
什麼問題?即使項目沒有運行,Logcat也會說出一些東西。你爲什麼不能運行它? –
我如何複製logcat? – coolcat
你有什麼錯誤?什麼是日食給你的信息。 – Gustek