【问题标题】:anyone see why my webview is not working任何人都知道为什么我的 webview 不起作用
【发布时间】:2012-01-19 08:09:40
【问题描述】:

我无法让我的 webview 活动调用任何人来查看问题所在。我有一个正在调用另一个列表视图的列表视图,但是当我单击第二个列表视图中的一个选项(应该打开一个 web 视图)时,什么也没有发生。感谢您的帮助

这是我第一个调用 webview 活动的活动

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class AccountingCourses extends ListActivity{
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String[] AccClasses = getResources().getStringArray(R.array.AccClasses);
    setListAdapter (new ArrayAdapter<String>(this, R.layout.list_view, AccClasses));


    getListView().setTextFilterEnabled(true);
}


    protected void onListItemCick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        Object o = this.getListAdapter().getItem(position);
        String account = o.toString();
        Intent returnIntent = new Intent();
        returnIntent.putExtra("Accounting", account);
        setResult(RESULT_OK,returnIntent);
        finish();



    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener (new OnItemClickListener()  {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Toast.makeText(getApplicationContext(), ((TextView) view) .getText(), Toast.LENGTH_SHORT) .show();

            if(position == 0)
            {
            Intent myIntent = new Intent (getApplicationContext(), (Fund_Acc.class));
            startActivityForResult(myIntent, 0);

这是我的 Webview 活动

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.ListView;

public class Fund_Acc extends ListActivity{

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);

    WebView wv = (WebView) findViewById(R.id.webview1); 
    wv.getSettings().setJavaScriptEnabled(true);
    wv.loadUrl("http://localhost/wordpress/?page_id=2");
}

protected void onListItemCick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Object a = this.getListAdapter().getItem(position);
    String Acc100 = a.toString();
    Intent returnIntent = new Intent();
    returnIntent.putExtra("Fund_Acc", Acc100);
    setResult(RESULT_OK,returnIntent);
    finish();
}

}

webview xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<WebView android:id="@+id/webview1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 

    />            

</LinearLayout>

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

    这是重现您的环境以准确说出发生了什么的方法。首先

    lv.setOnItemClickListener (new OnItemClickListener()
    ...
        if(position == 0)
        {
          // start Activity with WebView
        }
    

    你确定你的位置是0吗?尝试在开始 Activity 的位置设置断点,它可能从未被调用过。

    【讨论】:

    • 是的,它是第一选择,所以是 0 对吗?很抱歉,我不确定我是否理解你所说的断点
    • 为此行切换断点: Intent myIntent = new Intent (getApplicationContext(), (Fund_Acc.class));在调试模式下启动应用程序,单击列表中应使用 WebView 启动活动的第一项,应用程序的执行过程应在该断点处停止。鼠标右键单击该行,切换断点。
    猜你喜欢
    • 1970-01-01
    • 2018-01-30
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 2022-01-02
    • 1970-01-01
    • 2020-09-19
    相关资源
    最近更新 更多