Android 我有这个listview,我希望列表中的每一行都有webview,每个项目都有单独的webview

Android 我有这个listview,我希望列表中的每一行都有webview,每个项目都有单独的webview,android,android-listview,android-webview,Android,Android Listview,Android Webview,我的apidemo.java public class ApiDemos extends Activity { private ListView lv1; static final String[] COUNTRIES = new String[] { "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and

我的apidemo.java

public class ApiDemos extends Activity {
private ListView lv1;
static final String[] COUNTRIES = new String[] {
    "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
    "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina",
    "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan" };
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    lv1=(ListView)findViewById(R.id.ListView01);
    lv1.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1 , COUNTRIES));
}
公共类ApiDemos扩展活动{
私有ListView lv1;
静态最终字符串[]国家/地区=新字符串[]{
“阿富汗”、“阿尔巴尼亚”、“阿尔及利亚”、“美属萨摩亚”、“安道尔”,
“安哥拉”、“安圭拉”、“南极洲”、“安提瓜和巴布达”、“阿根廷”,
“亚美尼亚”、“阿鲁巴”、“澳大利亚”、“奥地利”、“阿塞拜疆”};
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv1=(ListView)findViewById(R.id.ListView01);
lv1.setAdapter(新的ArrayAdapter(这个,android.R.layout.simple_list_item_1,COUNTRIES));
}
}

在main.xml中,我有id为ListView01的ListView

我真正想要的是,阿富汗和其他国家的网络视图。 关于选择它们

***请尽快……紧急……******
我需要在我的学校提交项目

您只需要为listView设置一个监听器:

在顶部声明一个新的Webview,然后在此列表中,单击ListListener设置一个开关语句,根据单击的ListView中的哪个项目将URL分配给Webview。然后在switch语句的外面,但在侦听器的内部,调用WebView


希望这有帮助。

输出看起来像WebView显示为listview行项目。 遵循此指导原则

第一步。main_relLay.xml 用于添加滚动视图和线性布局

<RelativeLayout 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" >

<ScrollView
    android:id="@+id/scrollview"
    android:layout_width="fill_parent"
    android:layout_height="450dp" >

    <LinearLayout
        android:id="@+id/main_relLay"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#0B7A3B"
        android:orientation="vertical" >
    </LinearLayout>
</ScrollView>

</RelativeLayout>

说明:滚动视图用于listview效果。线性布局具有行的动态内容(WebView)

步骤2:row.xml 对于ListView行项目

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/row_relLay"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#F70925" >

    <ProgressBar
        android:id="@+id/progressbar"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="visible" />

    <WebView
        android:id="@+id/row_webView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:visibility="gone" >
    </WebView>
</RelativeLayout>

</LinearLayout>

描述:为listview行项目创建另一个xml

Java文件: 为listview行使用row.xml的LayoutFlater加载视图。 并将此row.xml添加到main.xml线性布局中,使其在滚动视图中可用,这是主线性布局提供的listview效果

步骤A:LinearLayout relLay=(LinearLayout)findViewById(R.id.main\u relLay)

步骤B:LayoutInflater充气器=(LayoutInflater)getApplication() .getSystemService(上下文布局\充气机\服务)

步骤C:查看v_child=充气机。充气(R.layout.row,空)


步骤D:relLay.addView(v_child)

听起来你应该早一点开始你的项目。很抱歉,rply太晚了。。。无论如何,我在医院里,我对switch语句并不感到困惑,它取决于哪些项目,我正在考虑使用一个新的textview而不是webview……好吧,switch语句是一个基本的java操作,类似于许多if和else语句。如果你需要澄清,就查一下。但是,您可以在switch语句的cases中使用每个元素的位置或名称(使用OnItemClickListener)来设置您想要将webview(或文本视图)设置为的内容。您只需使用McClickListener声明视图指向的位置,具体取决于您单击的项目。然后,一旦完成,您只需更改为视图