0

I set one Gribview and one listview in an Activity,In the Gridview there is a TextView and a Button,What I want do is ,when I click the button ,can add a data to the listView .and the button and listView in different layout files.

the xml code is :

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout  
  xmlns:android="http://schemas.android.com/apk/res/android"  
  android:id="@+id/root"  
  android:orientation="vertical"  
  android:layout_width="wrap_content"  
  android:layout_height="wrap_content"  
  android:layout_marginTop="5dp"  
  android:descendantFocusability="blocksDescendants" 
  >  



  <ImageView
  android:id="@+id/image"
  android:layout_width="180dp"
  android:layout_height="160dp"
  android:layout_gravity="fill"
  android:padding="4dp"
  android:scaleType="fitXY" />

  <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content">

  <LinearLayout android:orientation="vertical" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content">

  <TextView  
  android:id="@+id/title"  
  android:layout_width="wrap_content"  
  android:layout_height="wrap_content"  
  android:layout_gravity="center"  
  android:gravity="center_horizontal" 
  android:text="prices"  
  />  
  <TextView  
  android:id="@+id/prices"  
  android:layout_width="wrap_content"  
  android:layout_height="wrap_content"  
  android:layout_gravity="center"  
  android:gravity="center_horizontal"  
  android:text="name"  
  />  
  </LinearLayout>
  <LinearLayout android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_weight="9" />
  <Button 
  android:id="@+id/add"  
  android:layout_width="45dip"  
  android:layout_height="45dip"  
  android:layout_gravity="center"  
  android:gravity="center_horizontal" 
  android:text="+" 
  android:layout_weight="0.2"
  android:textSize="12pt"
  />
  </LinearLayout>
</LinearLayout>  

I want to realize when I click the button ,the sequence number of the image I pick can add to the listView.

ADD:

maybe I didn't say it clear.I have gridView and listView in one layout file.In the gridView I define an layout file ,which contain an ImageView and a Button.What I realize is ,when the app run,I have obtain the button's action in getView,What I want:in button events ,how to write the position values in listView.I haven't got the solution yet ,it really bother me ,thankx for any help.

ADD2:

Now I have achieved the adapter.notifyDataSetChanged()adding data in ListView.but I don't know how to obtain the string variable in Acitivity,the string variable is given by text(TextView android:id="@+id/prices") in ListView to Activity.When I refresh View(adapter.notifyDataSetChanged()),I get "0". why?could anyone help?thank a lot.

Toygirl
  • 79
  • 7

1 Answers1

0

You'll need to begin by adding a ListView to your layout file, and adding a button handler.

Take a look at Dynamically add elements to a listView Android

This links to a Stack Overflow question/answer that should get you started

Community
  • 1
  • 1
Shellum
  • 3,159
  • 2
  • 21
  • 26
  • If you know the solution of my question now? – Toygirl Nov 07 '12 at 09:31
  • I'm having trouble understanding your question. In response to "I don't know how to obtain the string variable in Acitivity"... Are you showing a price on each listview row? You should be able to use a custom list adapter (arrayadapter) class where you can access each row. In it's getView() method, you can manipulate any of the row's elements and get data from them as well. – Shellum Nov 07 '12 at 16:13