2013-05-20 5 views
0

이 코드를 사용하여 문제가 발생했지만이 오류를 해결하려고했지만 여전히 운이 없습니다. 나는 목록보기에서 항목을 내가 발견 된이 코드는 이제여러 활동을 클릭 할 때 클릭 가능

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 

     } 

내가 PRINT 로그 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> 
+0

무엇이 문제입니까? Logcat은 프로젝트가 실행되지 않아도 무언가를 알려줍니다. 왜 이걸 달릴 수 없니? –

+0

어떻게 logcat을 복사합니까? – coolcat

+0

가지고 계신 오류가 무엇입니까? 이클립스가 당신에게주는 메시지는 무엇입니까? – Gustek

답변

0

당신이 ListActivity을 확장하고 있기 때문에 캔트 SO 본 프로젝트를 실행 캔트 뭔가에게 또한 감사 p.s 말이냐 있으면 알려 주시기 바랍니다의 onItemClickListener가 작동하지 않습니다. onListItemClickListner를 사용해야하고 작동합니다.

+0

위의 코드를 편집했습니다 .. 그리고 내가 onlistitemclicklistener를 가져 오지 못하게하면 도움이 될 수 있습니까? – coolcat

+1

ListActivity를 확장하면 클릭 이벤트에 대한 리스너를 설정할 필요가 없습니다. 그냥 참조 여기에 더 많은 정보 클래스 보호 무효 onListItemClick() 에서이 메소드를 오버라이드 (override) : http://developer.android.com/reference/android/app/ListActivity.html –

0

ListActivity를 사용하고 있지만 사용자의보기에는 목록이 없습니다.

당신은 ListActivity를 사용할 수 있도록 레이아웃의 요소

<ListView 
    android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
</ListView> 

이 있어야합니다.

하지만 RelativeLayout 태그를 닫지 않아 일부 XML을 자른 것 같습니다.

+0

잘못된 XML..i 가지고 있었다 위의 XML을 변경했습니다. 내가 그걸 가지고 있다고 생각 했어.이 질문의 맨 위에있는 코드는 문제 였어? – coolcat

+0

ListActivity ListView를 사용하는 경우 @android : id/list – Gustek

+0

id가 있어야합니다. android : id = "@ + id/dialoglist" – coolcat

관련 문제