gpt4 book ai didi

java - 如何从 JavaScriptInterface 启动抽屉导航

转载 作者:行者123 更新时间:2023-12-03 10:23:35 25 4
gpt4 key购买 nike

我有 WebView 来显示我的网页,并且我想使用 Javascript 运行 Navigation Drawer

我的 logcat 没有显示任何错误消息,但它没有运行/

我的 JavaScript:

$('body').on("taphold", function ()
{
var checkboxes = document.getElementsByTagName('input');
for (var i = 0; i < checkboxes.length; i++)
{
if (checkboxes[i].type == 'checkbox')
{
checkboxes[i].checked = true;
}
}
AndroidFunction.DeleteAll();
}

Java:

public class MyJavaScriptInterface {
Context mContext;

MyJavaScriptInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public void DeleteAll()
{
//========== Array ================
final String[] fragments ={"Delete All"};
//=================================
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActionBar().getThemedContext(), android.R.layout.simple_list_item_1,fragments);
final DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
final ListView navList = (ListView) findViewById(R.id.drawer);
navList.setAdapter(adapter);
navList.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
@JavascriptInterface
public void onItemClick(AdapterView<?> parent, View view, final int pos,long id){
drawer.setDrawerListener( new DrawerLayout.SimpleDrawerListener(){
@Override
@JavascriptInterface
public void onDrawerClosed(View drawerView){
super.onDrawerClosed(drawerView);
switch (pos) {
case 0:
final SQLiteDatabase mydatabase = openOrCreateDatabase("CopyCollection", MODE_PRIVATE, null);
mydatabase.execSQL("DELETE * FROM Details;");
mydatabase.close();
myBrowser.loadUrl("javascript:fill_comment()");
break;
}
}
});
drawer.closeDrawer(navList);
}
});
}
}

最佳答案

据我了解,您想在调用 DeleteAll 方法时关闭抽屉,对吗?如果是这样,问题在于您正在将 drawer.closeDrawer(navList) 调用到匿名 OnItemClickListener 中。您必须将 closeDrawer 调用移出监听器对象,并将其放入 DeleteAll 方法作用域中。

关于java - 如何从 JavaScriptInterface 启动抽屉导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29517170/

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