I don't know if anyone knows how to do this... but if so, please help.
I'm trying to set a TextView I have in an xml. to a certain text with
an editText in a dialogBox. Currently my code will save the text and
put it in a random View in the ListView. I do NOT want that... I want
the text I save to go to a specific view and stay there.. anyone have
any suggestions? here is my Code: (The xml is below the code, and  all
I need is for it to save text in alarm_name_text and in ONE listView..
PLEASE HELP!)

package com.MTSUAndroid;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Button;
import android.widget.Toast;
import android.app.*;

public class AlarmList extends Activity {
        private static final int DIALOG_YES_NO_MESSAGE = 1;
        private static final int DIALOG_YES_NO_LONG_MESSAGE = 2;
        private static final int DIALOG_LIST = 3;
        private static final int DIALOG_PROGRESS = 4;
        private static final int DIALOG_SINGLE_CHOICE = 5;
        private static final int DIALOG_MULTIPLE_CHOICE = 6;
        private static final int DIALOG_TEXT_ENTRY = 7;

        private static final int MAX_PROGRESS = 100;
        private ProgressDialog mProgressDialog;
        private int mProgress;
        private Handler mProgressHandler;

        private ListView mainListView;
        private Planet[] planets;
        private static ArrayAdapter<Planet> listAdapter;
        private Button Save;
        private Button Default;
        private TextView text;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main3);

                AlertDialog.Builder alertBox = new AlertDialog.Builder(this);
                final TextView rowSavedText =
((TextView)findViewById(R.id.alarm_name_text));
                // Find the ListView resource.
                mainListView = (ListView) findViewById(R.id.mainListView);
                Save = (Button) findViewById(R.id.alarm_button);
                Default = (Button) findViewById(R.id.alarm_button1);
                text = (TextView)findViewById(R.id.alarm_name_text);
                Save.setOnClickListener(new Button.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                        }
                });
                Default.setOnClickListener(new Button.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                        }
                });
                // When item is tapped, toggle checked properties of CheckBox 
and
                // Planet.

                // Create and populate planets.
                planets = (Planet[]) getLastNonConfigurationInstance();
                if (planets == null) {
                        planets = new Planet[] { new Planet("Turn On Alarm"),
                                        new Planet("Alarm Name"), new 
Planet("Time"),
                                        new Planet("Sound"), new 
Planet("Vibrate"),
                                        new Planet("Repeat"), new 
Planet("Volume Control"),
                                        new Planet("Second Alarm") };
                }
                ArrayList<Planet> planetList = new ArrayList<Planet>();
                planetList.addAll(Arrays.asList(planets));
                // Set our custom array adapter as the ListView's adapter.
                listAdapter = new PlanetArrayAdapter(this, planetList);

                //int i = mainListView.getFirstVisiblePosition() + 1;
                mainListView.setAdapter(listAdapter);
                listAdapter.notifyDataSetChanged();
                listAdapter.notifyDataSetInvalidated();
                mainListView
                .setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View 
item,
                                        int position, long id) {
                                Planet planet = listAdapter.getItem(position);
                                planet.toggleChecked();
                                if (position == 1) {
                                        /*AlertDialog.Builder builder;
                                        AlertDialog alertDialog;
                                        Context mContext = 
getApplicationContext();
                                        LayoutInflater inflater = 
(LayoutInflater) mContext
                                                        
.getSystemService(LAYOUT_INFLATER_SERVICE);
                                        View layout = inflater.inflate(
                                                        R.layout.custom_dialog,
                                                        (ViewGroup) 
findViewById(R.id.layout_root));
                                        TextView text = (TextView) layout
                                                        
.findViewById(R.id.editText1);
                                        text.setText("HI THERE");
                                        builder = new 
AlertDialog.Builder(mContext);
                                        builder.setView(layout);
                                        alertDialog = builder.create();*/
                                        showDialog(DIALOG_TEXT_ENTRY);
                                }
                                PlanetViewHolder viewHolder = 
(PlanetViewHolder) item
                                                .getTag();
                                
viewHolder.getCheckBox().setChecked(planet.isChecked());
                        }
                });
        }

        @Override
        protected Dialog onCreateDialog(int id) {
                switch (id) {
                case DIALOG_TEXT_ENTRY:

                        LayoutInflater mInflater = LayoutInflater.from(this);
                        final View textEntryView = mInflater.inflate(
                                        R.layout.alert_text_entry, null);
                        /*final View textEntryView1 = 
mInflater.inflate(R.layout.row,
null);*/
                        final TextView rowSavedText =
((TextView)findViewById(R.id.alarm_name_text));
                        final EditText savedText =
((EditText)textEntryView.findViewById(R.id.password_edit));
                        return new AlertDialog.Builder(AlarmList.this)
                                        .setIcon(R.drawable.alert_icon)
                                        .setTitle("Enter your name")
                                        .setView(textEntryView)
                                        .setPositiveButton("accept",
                                                        new 
DialogInterface.OnClickListener() {
                                                                @Override
                                                                public void 
onClick(DialogInterface dialog,
                                                                                
int which) {
                                                                         String 
temp = savedText.getText().toString();
                                                                         
rowSavedText.setText(temp);

                                                                }
                                                        })
                                        .setNegativeButton("Cancel", new 
OnClickListener() {
                                                public void 
onClick(DialogInterface dialog, int which) {

                                                }
                                        }).create();
                }

                return null;
        }

        /** Holds planet data. */
        private static class Planet {
                private String name = "";
                private boolean checked = false;

                public Planet() {
                }

                public Planet(String name) {
                        this.name = name;
                }

                public Planet(String name, boolean checked) {
                        this.name = name;
                        this.checked = checked;
                }

                public String getName() {
                        return name;
                }

                public void setName(String name) {
                        this.name = name;
                }

                public boolean isChecked() {
                        return checked;
                }

                public void setChecked(boolean checked) {
                        this.checked = checked;
                }

                public String toString() {
                        return name;
                }

                public void toggleChecked() {
                        checked = !checked;
                }

        }

        /** Holds child views for one row. */
        private static class PlanetViewHolder {
                private CheckBox checkBox;
                private TextView textView;
                private TextView textView1;
                private Button button;

                public PlanetViewHolder() {
                }

                public PlanetViewHolder(TextView textView, CheckBox checkBox) {
                        this.checkBox = checkBox;
                        this.textView = textView;
                        this.button = button;
                        this.textView1 = textView1;
                }

                public CheckBox getCheckBox() {
                        return checkBox;
                }

                public void setCheckBox(CheckBox checkBox) {
                        this.checkBox = checkBox;
                }

                public TextView getTextView() {
                        return textView;
                }

                public void setTextView(TextView textView) {
                        this.textView = textView;
                }

                public TextView getButtonView() {
                        return button;
                }

                public void setButtonView(Button button) {
                        this.button = button;
                }
                public TextView getTextView1() {
                        return textView1;
                }

                public void setTextView1(TextView textView1) {
                        this.textView1=textView1;
                }
        }

        /** Custom adapter for displaying an array of Planet objects. */
        private class PlanetArrayAdapter extends ArrayAdapter<Planet> {

                private LayoutInflater inflater;
                public PlanetArrayAdapter(Context context, List<Planet> 
planetList)
{
                        super(context, R.layout.row, R.id.rowTextView, 
planetList);

                        // Cache the LayoutInflate to avoid asking for a new 
one each time.
                        inflater = LayoutInflater.from(context);

                }

                @Override
                public View getView(int position, View convertView, ViewGroup
parent) {
                        // Planet to display
                        Planet planet = (Planet) this.getItem(position);


                        // The child views in each row.
                        CheckBox checkBox;
                        TextView textView;
                        TextView textView1;
                        // Create a new row view
                        if (convertView == null) {
                                convertView = inflater.inflate(R.layout.row, 
null);

                                // Find the child views.
                                textView = (TextView) convertView
                                                .findViewById(R.id.rowTextView);
                                checkBox = (CheckBox) 
convertView.findViewById(R.id.CheckBox01);
                                textView1 = (TextView)
convertView.findViewById(R.id.alarm_name_text);
                                // Optimization: Tag the row with it's child 
views, so we don't
                                // have to
                                // call findViewById() later when we reuse the 
row.
                                convertView.setTag(new 
PlanetViewHolder(textView, checkBox));

                                // If CheckBox is toggled, update the planet it 
is tagged with.
                                checkBox.setOnClickListener(new 
View.OnClickListener() {
                                        public void onClick(View v) {
                                                CheckBox cb = (CheckBox) v;
                                                Planet planet = (Planet) 
cb.getTag();
                                                
planet.setChecked(cb.isChecked());
                                        }
                                });
                        }
                        // Reuse existing row view
                        else {
                                // Because we use a ViewHolder, we avoid having 
to call
                                // findViewById().
                                PlanetViewHolder viewHolder = 
(PlanetViewHolder) convertView
                                                .getTag();
                                checkBox = viewHolder.getCheckBox();
                                textView = viewHolder.getTextView();
                        }

                        // Tag the CheckBox with the Planet it is displaying, 
so that we
can
                        // access the planet in onClick() when the CheckBox is 
toggled.
                        checkBox.setTag(planet);

                        // Display planet data
                        checkBox.setChecked(planet.isChecked());
                        textView.setText(planet.getName());

                        return convertView;
                }

        }

        public Object onRetainNonConfigurationInstance() {
                return planets;
        }
}


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

  <TextView android:id="@+id/rowTextView"
    android:layout_width="wrap_content"
    android:layout_height="70dp"
    android:padding="12dp"
    android:textSize="16sp" >
  </TextView>

  <TextView android:id="@+id/alarm_name_text"
   android:layout_height="wrap_content"
   android:text=""
   android:layout_toRightOf="@+id/rowTextView"
   android:layout_width="fill_parent">
   </TextView>

  <CheckBox android:id="@+id/CheckBox01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:layout_alignParentRight="true"
android:layout_marginRight="6sp"
    android:focusable="false">
  </CheckBox>

</RelativeLayout>

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

Reply via email to