Hi!

I'm junior in andoid programming.
I would like to make a application in which there is an edit text and
if you write in a number and press a button, it would dinamically show
as many textview lines as the given number. The problem is that I
cannot number the textview lines. For example, if I write ten in the
edit text and press the button than number 9 will appear at the
beginning of all the lines. Could you help me with this problem?

Java:
package com.novoda;

import java.util.ArrayList;
import java.util.HashMap;
import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SimpleAdapter;

public class DynamicListItems extends ListActivity {

     private static final String ITEM_KEY = "key";
     ArrayList<HashMap<String, String>> list = new
ArrayList<HashMap<String, String>>();
     private EditText newValue;
     private SimpleAdapter notes;
     private int szam = 0;
     private int[] tomb = new int[10];
     private String[] key = new String[10];

     @Override
     public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.dynamic_list);

          newValue = (EditText) findViewById(R.id.new_value_field);

          notes = new SimpleAdapter(
                    this,
                    list,
                    R.layout.row,
                    new String[] { ITEM_KEY },
                    new int[] { R.id.list_value });

          Button ib = (Button) findViewById(R.id.button);

          ib.setOnClickListener(new View.OnClickListener() {
               public void onClick(View view) {
                    try {
                         szam =
Integer.valueOf(newValue.getText().toString()).intValue();
                         HashMap<String, String> item = new
HashMap<String, String>();
                         list.clear();
                         for(int i = 0;i < szam;i++){
                              item.put(ITEM_KEY, i+". line");
                              list.add(item);
                         }
                         setListAdapter(notes);

                    } catch (NullPointerException e) {
                         Log.i("[Dinamikus elemek]", "Megpróbáltál
hozzáadni egy null értéket.");
                    }
               }
          });
     }
}


dynamic_list.xml

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

     <TableLayout android:id="@+id/TableLayout01"
          android:layout_height="wrap_content"
android:orientation="vertical"
          android:layout_width="fill_parent">
          <EditText android:id="@+id/new_value_field"
               android:textColor="#020905"
               android:layout_marginTop="6px"
android:layout_marginBottom="8px"
               android:layout_width="fill_parent"
android:layout_height="fill_parent"
               android:layout_marginLeft="2px"
android:layout_marginRight="2px" />
          <Button android:text="Press" android:id="@+id/button"
               android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
     </TableLayout>
     <ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
          android:layout_height="0px" android:layout_weight="1"
          android:cacheColorHint="#00000000">
     </ListView>


</LinearLayout>


row.xml

XML:
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
     android:layout_width="fill_parent"
android:layout_height="wrap_content"
     android:background="#00000000">

     <TextView android:id="@+id/list_value"
android:layout_width="fill_parent"
          android:layout_height="wrap_content" />
</LinearLayout>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to