我有WebView
来显示我的网页,我希望Navigation Drawer
与Javascript
一起运行。
我的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();
}
爪哇:
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);
}
});
}
}
答案 0 :(得分:1)
据我所知,你想在调用DeleteAll
方法时关闭抽屉,对吧?如果是这样,问题是您要将drawer.closeDrawer(navList)
调用匿名OnItemClickListener
。您必须将closeDrawer
调用移出侦听器对象并将其放入DeleteAll
方法范围。