2013-07-05 3 views
0

나는 listview를 사용하고있다. 내 listview에서 나는 텍스트, 이미지 및 확인란을 가지고있다. 선택한 항목을 새 활력에 열어보고 싶습니다. 그러나 버튼을 클릭 할 때 항목을 선택하면 전체 목록이 다시 표시됩니다. 선택한 항목 만 표시하려고합니다.선택한 항목을 확인란에서 안드로이드의 다른 활동으로 보내는 방법은 무엇입니까?

MainActivity.java의 내 코드가

패키지 com.androidbegin.customimagelistview이다;

import java.util.ArrayList; 
import java.util.List; 

import android.os.Bundle; 
import android.app.Activity; 
import android.content.ClipData.Item; 
import android.content.Intent; 
import android.graphics.Path.FillType; 
import android.util.SparseBooleanArray; 
import android.view.Menu; 
import android.view.View.OnClickListener; 
import android.webkit.WebView.FindListener; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.ArrayAdapter; 
import android.widget.Button; 
import android.widget.CheckBox; 
import android.widget.CompoundButton; 
import android.widget.CompoundButton.OnCheckedChangeListener; 
import android.widget.ListView; 
import android.widget.TextView; 
import android.widget.Toast; 
import android.view.View; 

public class MainActivity extends Activity implements OnItemClickListener,      OnClickListener ,OnCheckedChangeListener { 

ArrayList<Model> model = new ArrayList<Model>(); 


// Declare Variables 
ListView list; 
ListViewAdapter adapter; 
String[] rank; 
String[] country; 
String[] population; 
int[] flag; 
//ArrayList<String> rank = new ArrayList<String>(); 
List<Model> list2=new ArrayList<Model>(); 
Button btn; 
Button getChoice; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.listview_main); 
    btn=(Button)findViewById(R.id.button1); 




    btn.setOnClickListener(this); 


    //getChoice = (Button)findViewById(R.id.button1); 
    //ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice,country); 

//adapter = new ListViewAdapter(this, model); 


    // Generate sample data 
    rank = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }; 

    country = new String[] { "China", "India", "United States", 
      "Indonesia", "Brazil", "Pakistan", "Nigeria", "Bangladesh", 
      "Russia", "Japan" }; 

    population = new String[] { "1,354,040,000", "1,210,193,422", 
      "315,761,000", "237,641,326", "193,946,886", "182,912,000", 
      "170,901,000", "152,518,015", "143,369,806", "127,360,000"       }; 

    flag = new int[] { R.drawable.china, R.drawable.india, 
      R.drawable.unitedstates, R.drawable.indonesia, 
      R.drawable.brazil, R.drawable.pakistan, R.drawable.nigeria, 
      R.drawable.bangladesh, R.drawable.russia, R.drawable.japan }; 

    // Locate the ListView in listview_main.xml 
    list = (ListView) findViewById(R.id.listview); 

    // Pass results to ListViewAdapter Class 
    adapter = new ListViewAdapter(this, rank, country, population, flag); 
    // Binds the Adapter to the ListView 
    list.setAdapter(adapter); 
    // Capture button clicks on ListView items 
    list.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> parent, final View view, 
       final int position, long id) { 

      SparseBooleanArray checked = list.getCheckedItemPositions(); 
      ArrayList<String> selectedItems= new ArrayList<String>(); 
      for(int i=0; i<checked.size();i++) 

      { 
       // Item position in adapter 
       int position1 = checked.keyAt(i); 
       // Add sport if it is checked i.e.) == TRUE! 
       if(checked.valueAt(i)) 
        selectedItems.add((String) adapter.getItem(position1)); 
       //oncheckedchANGElistner 

      } 

      String[] outputStrArr = new String[selectedItems.size()]; 
      for (int i = 0; i < selectedItems.size(); i++) { 
        outputStrArr[i] = selectedItems.get(i); 
       } 
      Intent intent = new Intent(getApplicationContext(),SingleItemView.class); 
       Bundle b = new Bundle(); 
       b.putStringArray("selectedItems", outputStrArr); 
       // Add the bundle to the intent. 
       intent.putExtras(b); 

       // start the ResultActivity 
       startActivity(intent); 

      TextView label = (TextView) view.getTag(R.id.rank); 
      CheckBox checkbox= (CheckBox) view.getTag(R.id.check); 
      Toast.makeText(view.getContext(), label.getText().toString()+ " " + isCheckedOrNot(checkbox), Toast.LENGTH_LONG).show(); 



      // Send single item click data to SingleItemView Class 
      Intent i = new Intent(MainActivity.this, SingleItemView.class); 
      // Pass all data rank 
      i.putExtra("rank", rank); 
      // Pass all data country 
      i.putExtra("country", country); 
      // Pass all data population 
      i.putExtra("population", population); 
      // Pass all data flag 
      i.putExtra("flag", flag); 
      // Pass a single position 
      i.putExtra("position", position); 
      // Open SingleItemView.java Activity 
      startActivity(i); 

     CheckBox chk = (CheckBox)view.findViewById(R.id.check); 

     final ArrayList<Integer> checkedPositions = new ArrayList<Integer>(); 
     chk.setOnCheckedChangeListener(new OnCheckedChangeListener() { 

      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
      { 

       if(isChecked=true) 
       { 
        checkedPositions.add(position); 

       } 

      } 

     }); 

    } 

     private String isCheckedOrNot(CheckBox checkbox) { 
      if (checkbox.isChecked()) 
       return "is checked"; 
      else 
       return "is not checked"; 
     } 
    }); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.activity_main, menu); 
    return true; 
} 

@Override 
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { 
} 

@Override 
public void onClick(View arg0) { 
    Intent i = new Intent(getApplicationContext(),SingleItemView.class); 
    i.putExtra("rank", rank); 
    i.putExtra("country", country); 
    i.putExtra("population", population); 
    i.putExtra("flag", flag); 
    startActivity(i); 

} 

@Override 
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 

} 

} 미리

감사합니다!

답변

0

..

목록보기에 OnItemClickListner 구현하고 당신이 당신의 텍스트, 이미지에 대한 목록보기 저장 한 정보 항목을 클릭하고 상자를 검사 할 때 ..

패스를 다른 활동 intent을 통해 정보와 거기에 표시

희망이 도움이 될 것입니다 ...

0

사용자가 배열의 데이터를 삽입 확인란을 선택하면 ListviewAdapter의 GetView 메서드에서 배열을 설정하십시오. 마지막으로 필요에 따라 Array에 액세스하십시오.

관련 문제