이와 비슷한 것을 만들고 싶습니다.안드로이드, tabhost 내부에서 버튼과리스트보기 undernetath를 추가하는 방법?
|
항목 1 개
항목 2
항목 3
. . . 목록보기의 항목
이미 탭이 3 개인 탭 호스트가 있으므로 버튼이 모든 탭에 표시되기 때문에 main.xml을 변경하지 않으려 고합니다. 첫 번째 탭에 캘린더를 표시하고 싶습니다 (이 중 하나는 완료되었지만 확인을 완료했는지는 확실하지 않습니다). 두 번째 탭에는 다른 항목이 표시되고 마지막에는 버튼과 항목 목록이 표시됩니다.
내가 한 모든 일은 안드로이드 튜토리얼에서 비롯된 것이므로 아무 것도 붙여 넣지 않으므로 누군가에게 나에게 이미 작성된 코드를 제공하고 싶지 않다. 그것을 달성하기 위해 봐라!
미리 감사드립니다.
음이 나는 이것이 내 주요 클래스입니다 지금까지 을 한 일입니다
이`공용 클래스 HourPayActivity이 TabActivity { 공공 무효에서 onCreate (번들 savedInstanceState) { super.onCreate (savedInstanceState)를 확장; setContentView (R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an //setContentView(R.layout.emptab); Activity for the tab (to be reused)
intent = new Intent().setClass(this, MonthsActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Months").setIndicator("",
res.getDrawable(R.drawable.ic_tab_months))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, EmployersActivity.class);
spec = tabHost.newTabSpec("Employers").setIndicator("",
res.getDrawable(R.drawable.ic_tab_employers))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, PaymentsActivity.class);
spec = tabHost.newTabSpec("Payments").setIndicator("",
res.getDrawable(R.drawable.ic_tab_payments))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
} `
그리고 이것은 내가 당신이 무엇을
public class EmployersActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView employersList = getListView();
String[] employers = getResources().getStringArray(R.array.employers_list);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, employers));
employersList.setAdapter(getListAdapter());
employersList.setTextFilterEnabled(true);
employersList.setOnItemClickListener(new OnItemClickListener() {
//@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_LONG).show();
}
});
setContentView(employersList);
}
우리는 탭을 구현하는 방법을 알아야합니다 ... 각 탭에 대한 활동을 사용하고 있습니까? 조각을 사용하고 있습니까? 당신은 각각에 대한 활동과 조각을 사용하고 있습니까? 질문에 답변하기에 충분한 정보를 제공하지 않았습니다. 아, 주 XML에 버튼을 추가하는 것에 대한 귀하의 주장이 올바르지 않습니다. 기본 레이아웃 xml을 설정하고 탭으로 코딩 된 각 탭에 대해 별도의보기를 가질 수 있습니다 (다시, 탭 수행 방법에 따라 다름). – Barak
답변 해 주셔서 감사합니다. Hello views-> Tab View에서 android tutorial을 사용하여 탭을 만들었습니다. 그래서 나는 그들이 각 탭에 대해 다른 활동을 사용하여 만들어 졌다고 생각합니다! 미안하지만 내 "빠른"질문에 대한 미안하지만 난 안돼서 : P는 안드로이드에 – ASK
단지 몇 가지 팁, 당신은 의도의 생성자를 사용하여 클래스 이름을 전달할 수 있습니다. 메소드 호출을 저장합니다. 새로운 인 텐트 (this, activity.class); 예를 들면. 또한, "extends Activity"를 "extends ListActivity"로 변경하면 ListActivity의 listview에 onClickListener를 추가 할 수 있습니다. setOnItemClickListener() –