gpt4 book ai didi

android - 在抽屉导航中,onitemclicklistener 不工作。抽屉运行良好

转载 作者:行者123 更新时间:2023-11-30 02:40:20 25 4
gpt4 key购买 nike

我正在处理一个应用程序,但在抽屉导航中 onitemclicklistener 不工作,但抽屉运行良好。 Logcat 显示

09-15 16:41:26.568: D/AbsListView(22587): onVisibilityChanged() is called, visibility : 0
09-15 16:41:26.568: D/AbsListView(22587): unregisterIRListener() is called
09-15 16:41:26.678: D/AbsListView(22587): unregisterIRListener() is called
09-15 16:41:29.070: D/AbsListView(22587): onVisibilityChanged() is called, visibility : 4
09-15 16:41:29.080: D/AbsListView(22587): unregisterIRListener() is called
09-15 16:41:29.100: D/AbsListView(22587): unregisterIRListener() is called
09-15 16:41:29.571: I/net.wigle.wigleandroid.ZoomButtonsController(22587):

调用:onVisibilityChanged 监听器:org.osmdroid.views.MapView$MapViewZoomListener@41baeee8

我用了这段代码

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
mapBeginConfig();
loadUI();
mapEndConfig();

sims = getResources().getStringArray(R.array.myItems);
drawer = (DrawerLayout) findViewById(R.id.drawerlayout);
drawertoggle = new ActionBarDrawerToggle(this, drawer, R.drawable.ic_action_overflow, R.string.drawer_open, R.string.drawer_Close) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}

@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}

};
drawer.setDrawerListener(drawertoggle);


// sims = getResources().getStringArray(R.array.myItems);
list = (ListView) findViewById(R.id.list);
list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, sims));
list.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, sims[position], Toast.LENGTH_SHORT).show();
}
});
}

项目的xml代码

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<FrameLayout
android:id="@+id/maincontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>

<ListView
android:id="@+id/list"
android:layout_width="130dp"
android:layout_height="fill_parent"
android:layout_gravity="start"
android:background="#ff8800"
android:divider="@null" >
</ListView>

    private void mapBeginConfig() {
mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
SimpleRegisterReceiver simpleReceiver = new SimpleRegisterReceiver(this);

// File f = new File(Environment.getExternalStorageDirectory(),
// "Atlas.mbtiles");
File f = new File(getCacheDir() + "/Atlascities.mbtiles");
if (!f.exists())
try {

InputStream is = getAssets().open("Atlascities.mbtiles");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();

FileOutputStream fos = new FileOutputStream(f);
fos.write(buffer);
fos.close();
} catch (Exception e) {
// TODO: handle exception
}

IArchiveFile[] files = { MBTilesFileArchive.getDatabaseFileArchive(f) };
MapTileModuleProviderBase moduleProvider = new MapTileFileArchiveProvider(
simpleReceiver, MBTILESRENDER, files);

mProvider = new MapTileProviderArray(MBTILESRENDER, null,
new MapTileModuleProviderBase[] { moduleProvider });

// this.mOsmv= new
// com.mapbox.mapboxsdk.views.MapView(this,(AttributeSet) mResourceProxy
// );
this.mOsmv = new MapView(this, 256, mResourceProxy, mProvider);

}



private void mapEndConfig() {

this.mOsmv.setBuiltInZoomControls(true);

this.mOsmv.setMultiTouchControls(true);

mOsmv.getController().setZoom(2);

double lon = 0;

double lat = 0;



IGeoPoint point = new GeoPoint(lat, lon); // lat lon and not inverse

mOsmv.getController().setCenter(point);
}


private void loadUI() {

this.setContentView(R.layout.activity_main);

// RelativeLayout rl = (RelativeLayout) findViewById(R.id.relative);

DrawerLayout rl = (DrawerLayout) findViewById(R.id.drawerlayout);

this.mOsmv.setLayoutParams(new LinearLayout.LayoutParams(

LinearLayout.LayoutParams.FILL_PARENT,

LinearLayout.LayoutParams.FILL_PARENT));

rl.addView(this.mOsmv);
}

}

最佳答案

问题出在 loadUI() 方法中。您正在将 View mOsmv 直接添加到 DrawerLayout,导致它在抽屉上方按 z 顺序排列,并干扰点击事件。 View 应添加到内容 View - FrameLayout maincontent - 如下所示:

private void loadUI()
{
setContentView(R.layout.activity_main);

FrameLayout fl = (FrameLayout) findViewById(R.id.maincontent);
mOsmv.setLayoutParams(new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
fl.addView(mOsmv);
}

关于android - 在抽屉导航中,onitemclicklistener 不工作。抽屉运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25846789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com