2012-11-22 6 views
-1

나는 안드로이드 응용 프로그램과 함께 일하고 있습니다. 우선, webservice의 모든 데이터를 저장하고 나중에 db의 데이터를 쿼리하고 listview에서 업데이트해야합니다.목록보기에서 자식 활동 시작 버튼 안드로이드 클릭하십시오

내 listview 항목에 체크 박스와 버튼이 있습니다. 버튼이나 체크 박스를 클릭하면 잘 동작하고 (LOG 표시),리스트 뷰에서 버튼을 클릭하면 하위 작업을 시작해야합니다.

이 내 어댑터 클래스

public class GuestListAdapter extends BaseAdapter{ 
    Context context; 
    ArrayList<String > arrayListFirstValue; 
    ArrayList<String > arrayListSecondValue; 
    ArrayList<String > arrayListThirdValue; 
    public GuestListAdapter(Context mcontext, ArrayList<String> arrListFV,ArrayList<String> arrListSV,ArrayList<String> arrListGuestTV) 
    { 
     arrayListFirstValue =arrListFV; 
     arrayListSecondValue =arrLisSV; 
     arrayListThirdValue =arrListTV; 
     context = mcontext; 
    } 

    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return arrayListFirstValue.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     // TODO Auto-generated method stub 
     return arrayListFirstValue.get(position); 
    } 

    @Override 
    public long getItemId(int position) { 
     // TODO Auto-generated method stub 
     return position; 
    } 

    @Override 
    public View getView(int position, View view, ViewGroup parent) { 
     // TODO Auto-generated method stub 
     if (view == null) { 
       LayoutInflater inflater = LayoutInflater.from(parent.getContext()); 
       view = inflater.inflate(R.layout.guest_list_item, parent, false); 
      } 



     TextView txtFirstValue = (TextView)view.findViewById(R.id.txt_firstname); 
      txtFirstValue .setText(arrayListFirstValue.get(position)); 
     TextView txtSecondValue = (TextView)view.findViewById(R.id.txt_lastname); 
     txtSecondValue .setText(arrayListSecondValue.get(position)); 
     TextView txtThirdValue = (TextView)view.findViewById(R.id.txt_guest_count); 
     txtThirdValue .setText(arrayListThirdValue.get(position)); 
     Button btnInfo = (Button)view.findViewById(R.id.btn_info); 

     CheckBox checkBoxCheckins = (CheckBox)view.findViewById(R.id.checkBoxIsCheckedIn); 


     btnInfo.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 

       System.out.println("Adap button **********"); 

      } 
     }); 
     checkBoxCheckins.setOnCheckedChangeListener(new OnCheckedChangeListener() { 

      @Override 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
       System.out.println("Adap checked **********"); 

      } 
     }); 

     return view; 
    } 


} 

마지막으로 내 질문에 내가 목록보기에서 버튼을 클릭하면 자식 활동을 시작할 필요가있다입니다. 이 방법을 알려주십시오.

Intent intent = new Intent(context,Activity.class); 
startActivity(intent); 

답변

0

는이 같은가 어댑터로 전달 활동의 컨텍스트를 사용하여 새 활동을 시작 juste 있습니다. 현재 청취자를 다음으로 변경하십시오.

편집 : 처음에는 탭의 하위 작업에서 해당 목록보기를 말하지 않기 때문에. 당신의 탭 활동 (부모 활동)에서

btnInfo.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 

        Intent intent = new Intent(context, YourNewTabActivity.class);// Your tab parent activity. 
intent.putExtra(Constants.TAB_INDEX, tab index number) // pass the index of the tab you want to move to. 

    startActivity(intent); 

       } 
      }); 

, 당신은 onCreate

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 



      setContentView(R.layout.main_tab_screen); 
      tabHost = (TabHost) findViewById(android.R.id.tabhost); 
      tabWidget = getTabWidget(); 


      if (getIntent().getExtras() != null) { 
       tabindex = getIntent().getExtras().getInt(Constants.TAB_INDEX, 
         0); // you check if this parent started from other activity. You child activity will pass the desire tab index here. If nothing is special, just display the 1st tab. 
          } 
      initTab(); 
     } 
    } 



    protected void initTab() { 
     Intent intent; 
     TabHost.TabSpec spec; 
     // Add tab child 
     spec = tabHost.newTabSpec("Inbox").setIndicator(
       getTabIndicatorView(MainTabActivity.this, "Hộp thư", 
         R.drawable.tin_nhan_tab_selector)); 
     intent = new Intent(this, com.vtcmobile.ui.InboxActivity.class); 
     // intent.putExtra(Constants.INTENT_IS_LOAD, isload); 
     spec.setContent(intent); 
     tabHost.addTab(spec); 
.... 

     tabHost.setCurrentTab(tabindex); // use the tab index to get the right tab you want. 
     tabHost.getTabWidget().focusCurrentTab(tabindex); 

    } 
0

그것은 매우 간단합니다 :

+0

프로그램 작품에 당신의 욕망 탭

private int tabindex = 0; 

확인이의 인덱스를 저장하고 인쇄 할 수있는 변수를 생성 로그하지만 문제는 자식 활동을 시작할 수 없다는 것을 기억하고, 한 가지만 기억하면, 사용자 지정 어댑터 클래스 (기본 어댑터)에서 활동이 확장되어 활동을 시작할 수 없거나 자식 활동을 시작할 수 없습니다. 지. 사용자 지정 어댑터 클래스 또는 내 문제에 대한 모든 솔루션에서 자식 작업을 시작할 수있는 방법이 있습니까? – Dhamodharan

+0

어댑터 컨스트럭터에 컨텍스트가 있음을 확인했습니다. 당신은'onClick'에서 그 문맥을 전달합니다. –

+0

먼저 답장을 보내 주셔서 감사합니다.하지만 여기서 한가지 말씀 드리지만 탭 표시 줄에 목록보기를 표시하고 있습니다. 목록 항목에서 버튼을 클릭하면 탭 막대에서 다른 활동으로 이동해야합니다. 그래서 저는 어린이 활동을 시작해야합니다. 정상적인 의도는 아닙니다. 제발 나를 안내 해줘. – Dhamodharan