TextView的Android ListView定位

TextView的Android ListView定位,android,listview,textview,position,dialog,Android,Listview,Textview,Position,Dialog,我真的不知道从哪里开始问这个问题,所以我将尽我所能描述我的问题…我目前正在使用一个自定义列表适配器处理一个ListView,该适配器可以膨胀两个文本视图和一个复选框。一个文本视图是对该选项的描述,其中另一个文本视图是为我需要使用它来显示数据而保存的。当用户单击列表中的项目时,将弹出一个editText对话框。我用它来保存文本并显示它,但我遇到的问题是,当它显示数据时,它不在正确的ListView项上。。。例如: 假设我想在listView的第一个窗口中显示从对话框中获得的信息。它在第三、第二或第

我真的不知道从哪里开始问这个问题,所以我将尽我所能描述我的问题…我目前正在使用一个自定义列表适配器处理一个ListView,该适配器可以膨胀两个文本视图和一个复选框。一个文本视图是对该选项的描述,其中另一个文本视图是为我需要使用它来显示数据而保存的。当用户单击列表中的项目时,将弹出一个editText对话框。我用它来保存文本并显示它,但我遇到的问题是,当它显示数据时,它不在正确的ListView项上。。。例如: 假设我想在listView的第一个窗口中显示从对话框中获得的信息。它在第三、第二或第四位置随机显示。这似乎是一个很简单的问题,但我已经挣扎了一段时间

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>
如果有人想看到我的代码的任何其他部分来帮助我,请让我知道。提前谢谢

以下是我的列表适配器和其中的数据:

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


listAdapter = new PlanetArrayAdapter(this, planetList);
Planet=newplanet[]{newplanet(“打开警报”),
新行星(“报警名称”)、新行星(“时间”),
新行星(“声音”)、新行星(“振动”),
新行星(“重复”),新行星(“音量控制”),
新行星(“第二次警报”);
}
ArrayList planetList=新的ArrayList();
planetList.addAll(Arrays.asList(planets));
listAdapter=新天文馆适配器(此,planetList);
/**用于显示行星对象阵列的自定义适配器*/ 专用类天文馆适配器扩展阵列适配器{

    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;
        Spinner mySpinner;


// 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);
                // 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;
        }
私人充气机;
公共天文馆适配器(上下文上下文,列表天文馆列表){
super(上下文、R.layout.row、R.id.rowTextView、planetList);
//缓存LayoutFlate以避免每次请求新的LayoutFlate。
充气器=充气器。从(上下文);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
//要显示的行星
行星=(行星)this.getItem(位置);
//每行中的子视图。
复选框;
文本视图文本视图;
纺纱机;
//创建新的行视图
if(convertView==null){
convertView=充气机充气(R.layout.row,空);
//查找子视图。
textView=(textView)convertView
.findViewById(R.id.rowTextView);
复选框=(复选框)convertView.findViewById(R.id.CheckBox01);
//优化:用行的子视图标记行,这样我们就不会
//不得不
//稍后当我们重用行时调用findViewById()。
setTag(新的PlanetViewHolder(textView,复选框));
//如果选中复选框,则更新其标记的行星。
checkBox.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
复选框cb=(复选框)v;
行星=(行星)cb.getTag();
planet.setChecked(cb.isChecked());
}
});
}
//重用现有行视图
否则{
//因为我们使用了一个ViewHolder,所以我们避免了调用
//findViewById()。
平面视图支架=(平面视图支架)转换视图
.getTag();
checkBox=viewHolder.getCheckBox();
textView=viewHolder.getTextView();
}
//在复选框上标记它正在显示的行星,以便我们可以
//选中复选框时,在onClick()中访问行星。
复选框.setTag(行星);
//显示行星数据
checkBox.setChecked(planet.isChecked());
textView.setText(planet.getName());
返回视图;
}

不要认为您可以从对话框视图中设置这些文本视图。您必须从自定义列表适配器中设置它们。像现在一样从对话框中获取名称,然后将名称添加到自定义适配器的数据集中,最后重新设置适配器或notifyDataSetChanged().

我不太明白你的意思。如果我如何从dialogView中获取名称,然后在范围之外使用它?另外,我是否应该在getView()中设置TextView方法?当我添加数据集时,我是在传递它吗?还是只是定义一段数据..对不起,我对android非常陌生,我们学院没有教师。从对话框中获取文本,然后将其添加到ArrayList或适配器使用的任何结构中,添加时,调用游标。notifySethDataSanged(),然后光标将重新填充listview,并将对话框中的数据放置在listview中。别忘了调用光标。notifyDataSetInvalidated();这将导致listview重新绘制自身,包括新数据。我打赌这就是您正在尝试的。有没有办法在聊天中交谈?您所说的实际上是有意义的,我只是不确定如何添加该字符串。我的意思是,文本正在存储并放入其中一个listview视图的textView中。只是不是正确的视图istview是多个视图。它就像一堆视图。当您从对话框调用rowSavedText.setText(temp)时,它会在适配器当时正在绘制/设置的任何视图上设置它。这就是为什么您必须在arraylist/adapter上进行更改,然后让它重新填充listview。您可以发布自定义列表适配器吗?
    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;
        Spinner mySpinner;


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