开发者

I have this listview, i want webview for every row in the list, seperate webview for every item

开发者 https://www.devze.com 2023-02-03 12:50 出处:网络
my apidemo.java public class ApiDemos extends Activity { private ListView lv1; static final String[] COUNTRIES = new String[] {

my 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));
}

}

and in my main.xml, i have ListView with id:ListView01

want i really want is, a webview for afghanistan, and fo开发者_StackOverflow中文版r rest countries. on selecting them.

*PLZ rply soon.....URGENT......****** i hv to submit the project IN MY SCHOOL__


you just need to set up an OnItemClickListener for the listView:

http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html

Declare a new Webview at the top then within this OnItemClickListener set up a switch statment to assign the URL to the WebView depending on which item in the ListView was clicked. Then out side of the switch statment, but inside the OnItemClickListener, call on the WebView.

Hope this helps.


Output look like WebView showing as listview row item. Follow this guidelines.

Step 1. main_relLay.xml For adding scroll view and linear layout

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

Description: ScrollView use for listview effect. Linear Layout have a dynamic content (WebView) of rows.

Step 2: row.xml For ListView row item

<?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>

Description: Create another xml for listview row items.

Java file : Using LayoutInflater load view of row.xml for listview row. And add this row.xml in main.xml linear layout its avaialable in scroll view, This is main linear layout provide listview effect.

Step A: LinearLayout relLay = (LinearLayout) findViewById(R.id.main_relLay);

Step B: LayoutInflater inflater = (LayoutInflater) getApplication() .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

Step C: View v_child = inflater.inflate(R.layout.row, null);

Step D: relLay.addView(v_child);

0

精彩评论

暂无评论...
验证码 换一张
取 消