2016-03-08 36 views
0

在我的課程應用程序中,我列出了包含子課程的課程列表。課程顯示在自定義列表中。一旦用戶點擊課程名稱,特別課程活動將隨課程的詳細信息打開。在該活動的「課程內容」文本視圖中單擊監聽器。用戶單擊該文本查看具有特定課程的子課程的自定義列表將被打開。我試圖在每門課程的所有子課程中使用相同的自定義列表。而不是爲每門課程創建單獨的自定義列表。我試圖通過將課程活動的圖像數組和課程標題數組通過Intent發送到自定義列表活動來實現此目的。但同時單擊課程內容文本查看自定義列表活動停止unfortunately.Here錯誤重複使用所有活動中的自定義列表

enter image description here

BigdataActivity(當然活動)

public class BigdataActivity extends Activity { 

ImageView logo; 
Button phone,mail,whatsapp; 
TextView course; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
      WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.activity_bigdata); 

    logo=(ImageView) findViewById(R.id.imageView1); 
    LayoutParams params = (LayoutParams) logo.getLayoutParams(); 
    params.width = 350; params.height=150; params.leftMargin=150; 
    logo.setLayoutParams(params); 
    course=(TextView) findViewById(R.id.course); 
    phone=(Button) findViewById(R.id.button1); 
    mail=(Button) findViewById(R.id.button2); 
    whatsapp=(Button) findViewById(R.id.button3); 
    course.setOnClickListener(new OnClickListener() { 



     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      //MyAlert alert=new MyAlert(); 
      //alert.show(getFragmentManager(), "Fill the Form"); 

      int activity=1; 
      Resources res=getResources(); 
      String[] courseTitle=res.getStringArray(R.array.BigData); 
      int image[] = 
      { 
       R.drawable.bigdatahad, 
       R.drawable.hadoopadmin,R.drawable.bigdataanalytics, 
       R.drawable.testing 
      }; 
      Intent intent=new 
      Intent(BigdataActivity.this,BDataDialog.class); 
      intent.putExtra("img", image); 
      intent.putExtra("course", courseTitle); 
      intent.putExtra("activity", activity); 
      startActivity(intent); 





     } 


    }); 
    phone.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 

      String no="+9187"; 
      Intent callintent =new Intent(Intent.ACTION_CALL); 
      callintent.setData(Uri.parse("tel:"+no)); 
      startActivity(callintent); 

     } 
    }); 

    mail.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 

      Intent mailintent= new Intent(Intent.ACTION_SEND); 
      mailintent.setData(Uri.parse("mailto:")); 
      String[] toadd={"[email protected]"}; 
      mailintent.putExtra(Intent.EXTRA_EMAIL,toadd); 
      mailintent.setType("message/rfc822"); 
      Intent chooser = mailintent.createChooser(mailintent, "Send 
      Email"); 
      startActivity(chooser); 
     } 
    }); 

    whatsapp.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 

      String cont="7290"; 
      openWhatsappContact(cont); 

     } 
    }); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.bigdata, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // TODO Auto-generated method stub 
    int id = item.getItemId(); 
    if(id==R.id.action_settings){ 

     startActivityForResult(new 
     Intent(android.provider.Settings.ACTION_SETTINGS), 0); 

    } 
    return super.onOptionsItemSelected(item); 
} 


void openWhatsappContact(String number) { 


     Uri uri = Uri.parse("smsto:" + number); 
     Intent i = new Intent(Intent.ACTION_SENDTO, uri); 
     i.setPackage("com.whatsapp"); 
     startActivity(Intent.createChooser(i, "")); 

} 

}

自定義列表活動列出子課程

公共類BDataDialog延伸活動{

ImageView logoview; 
ListView list; 
String[] courseTitle=getIntent().getStringArrayExtra("course"); 
int image[]=getIntent().getIntArrayExtra("img"); 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
      WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.activity_bdata_dialog); 
    //logoview=(ImageView) findViewById(R.id.imageView1); 
    list=(ListView) findViewById(R.id.listView1); 


    // list.setVisibility(View.INVISIBLE); 
    /* Resources res=getResources(); 
    courseTitle=res.getStringArray(R.array.BData);*/ 
    CourseAdapter listAdapter =new CourseAdapter(this, courseTitle, image); 
    list.setAdapter(listAdapter); 

    list.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> adapter, View arg1, int position, 
       long id) { 
      // TODO Auto-generated method stub 
      String value = (String)adapter.getItemAtPosition(position); 
      int activity =getIntent().getIntExtra("activity", 0); 

      if (value == courseTitle[0]){ 

       switch(activity){ 
       case 1: 
        Uri uriUrl = Uri.parse("http://www.jpasolutions.net/coursedetails.php?cat_id=1&crs_id=1&sub_id=1"); 
        Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl); 
        startActivity(launchBrowser); 
        finish(); 
        break; 
       case 2: 

        Uri uriUrl1 = Uri.parse("http://www.jpasolutions.net/coursedetails.php?cat_id=1&crs_id=24&sub_id=1"); 
        Intent launchBrowser1 = new Intent(Intent.ACTION_VIEW, uriUrl1); 
        startActivity(launchBrowser1); 
        finish(); 
        break; 
       } 


      } 
      else{ 

       Uri uriUrl = Uri.parse("http://www.jpasolutions.net/coursedetails.php?cat_id=1&crs_id=32&sub_id=1"); 
       Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl); 
       startActivity(launchBrowser); 
       finish(); 
      } 



     } 



    }); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.bdata_dialog, menu); 
    return true; 
} 

}

類CourseAdapter擴展ArrayAdapter {

Context context; int images[];String titleArray[]; 
CourseAdapter(Context ctx,String[] courseTitle, int imgs[]) 
{ 
    super(ctx,R.layout.courseslist,R.id.textView1,courseTitle); 
    this.context=ctx; 
    this.images=imgs; 
    this.titleArray=courseTitle; 

} 

public View getView(int position, View convertView, ViewGroup parent) 
{ 
    // TODO Auto-generated method stub 
    LayoutInflater inflater=(LayoutInflater) 
    context.getSystemService(context.LAYOUT_INFLATER_SERVICE); 
    View row=inflater.inflate(R.layout.courseslist, parent, false); 

    ImageView myimage=(ImageView) row.findViewById(R.id.imageView1); 
    TextView textview=(TextView) row.findViewById(R.id.textView1); 

    myimage.setImageResource(images[position]); 
    textview.setText(titleArray[position]); 

    return row; 
} 

}

請幫我解決這個問題。

回答

0

getIntent().getStringArrayExtra("course")被返回null ...

嘗試:

  • 手柄內oncreate這getIntent()事件。當你穿上意圖演員,發射活動前,如果 他們

  • 驗證不是空現在

+0

其工作。謝謝... – mani

相關問題