0
내 문제는 onItemClickListener가 내 탐색 창에서 작동하지 않습니다. 또한 TabActivity를 내 MainActivity에 사용하고 있습니다. TabActivity의 다른 모든 항목이 정상적으로 작동하고 있습니다. 또한 .... 그것은 또한 작동하지 않습니다 .. setOnItemSelectedListener을 시도 미리 감사드립니다탐색 창에서 onitemclicklistener가 TabActivity에서 작동하지 않습니다.
activity_main.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawerlayout"
tools:context=".MainActivity" >
<FrameLayout
android:id="@+id/maincontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<ListView android:id="@+id/listview"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#18FFFF">
</ListView>
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
</android.support.v4.widget.DrawerLayout>
MainActivity.java
public class MainActivity extends TabActivity implements AdapterView.OnItemClickListener {
ActionBar actionbar;
private DrawerLayout dl;
private ListView l;
private String[] navimenu = {"Home", "Sell My Mobile", "Top 20 List", "Log Out"};
private ActionBarDrawerToggle drawerlistener;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dl = (DrawerLayout)findViewById(R.id.drawerlayout);
l = (ListView)findViewById(R.id.listview);
l.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, navimenu));
l.setOnItemClickListener(this);
drawerlistener = new ActionBarDrawerToggle(this, dl, R.drawable.hi, R.string.drawer_open, R.string.drawer_close){
@Override
public void onDrawerOpened(View drawerView) {
// TODO Auto-generated method stub
super.onDrawerOpened(drawerView);
}
@Override
public void onDrawerClosed(View drawerView) {
// TODO Auto-generated method stub
super.onDrawerClosed(drawerView);
}
};
dl.setDrawerListener(drawerlistener);
actionbar = getActionBar();
actionbar.setHomeButtonEnabled(true);
actionbar.setDisplayHomeAsUpEnabled(true);
// for Tab
TabHost tabhost = getTabHost();
TabHost.TabSpec newspec = tabhost.newTabSpec("New Phones");
newspec.setIndicator("New Phones");
Intent ni = new Intent(this, Newphone.class);
newspec.setContent(ni);
TabHost.TabSpec oldspec = tabhost.newTabSpec("Old Phones");
oldspec.setIndicator("Old Phones");
Intent oi = new Intent(this, Oldphone.class);
oldspec.setContent(oi);
TabHost.TabSpec sspec = tabhost.newTabSpec("Services");
sspec.setIndicator("services");
Intent si = new Intent(this, Services.class);
sspec.setContent(si);
tabhost.addTab(newspec);
tabhost.addTab(oldspec);
tabhost.addTab(sspec);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerlistener.onConfigurationChanged(newConfig);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(drawerlistener.onOptionsItemSelected(item)){
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerlistener.syncState();
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Toast.makeText(this, "jello", Toast.LENGTH_SHORT).show();
switch(position){
case 0 :
Intent home = new Intent(this, MainActivity.class);
startActivity(home);
case 1 :
Intent smm = new Intent(this, Sellmymobile.class);
startActivity(smm);
case 2:
Intent t2l = new Intent(this, Top2l.class);
startActivity(t2l);
case 3:
Intent lo = new Intent(this, Login.class);
startActivity(lo);
}
selectItem(position);
}
private void selectItem(int position) {
l.setItemChecked(position, true);
setTitle(navimenu[position]);
}
@Override
public void setTitle(CharSequence title) {
actionbar.setTitle(title);
}
}
그것은 완벽하게 작동 ... 매우 유 감사합니다 ... 내가 변경 내 XML 파일 및 그것은 일했다 :) – aswin
그거 멋지 네요. 나는 그것이 당신을 도왔다 니 다행이다. D –
나중에 다른 활동에 갔다가 그 탐색 서랍이 나타나지 않는다. .. 이걸 어떻게 풀 수 있는지 알고 있니? – aswin