Android simpleCursorAdapter回收视图可见性问题

时间:2013-01-06 10:03:50

标签: android listactivity simplecursoradapter

我正在尝试实现扩展ListActivity的类。 ListActivity中的每一行都会通过单击来扩展。它通过将组件的可见性从行更改为“可见”或“消失”来实现。 当我扩展一行时会出现问题。向下滚动时,会有不同的行在不单击的情况下展开。 我读到了它,并看到simpleCursorAdapter类回收了视图,我认为这会导致问题。

我该如何避免这种情况?使用simpleCursorAdapter是正确的方法还是有其他解决方案来处理这种情况?

感谢。

代码:

public class MakeSearchActivity extends ListActivity {
public  Object [][] dataToRows;
private String dataReceived;
private MatrixCursor matrixForAdapter;

@Override
public void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);
    setContentView(R.layout.activity_make_search);
    Intent intent=getIntent();

    dataReceived=intent.getStringExtra(Globals.returnedFromSearch);

    String [] titles={"_id","origin", "dest", "date", "hour", "price","name", "phone", "comments"};
    matrixForAdapter = new MatrixCursor(titles);
    fill_dataToRows();

    String [] from=new String[]{"origin", "dest", "date", "hour" ,"price","name", "phone", "comments"};
    int[] to = new int[] { R.id.originData, R.id.destData,R.id.dateData,R.id.hourData ,R.id.priceData ,R.id.nameData ,R.id.phoneData ,R.id.commentsData};

    // create the adapter using the cursor pointing to the desired data as well as the layout information
    SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.activity_result_entry, matrixForAdapter, from, to);

    // set this adapter as your ListActivity's adapter
    this.setListAdapter(mAdapter);

}


private void fill_dataToRows() {
    //function that fill the Matrix by using matrixForAdapter.addRow(tremps[i]);
}


public void clickedOnRow(View view)
{
    TextView phoneDataText=(TextView) view.findViewById(R.id.phoneData);
    TextView commentsDataText=(TextView) view.findViewById(R.id.commentsData);
    TextView nameDataText=(TextView) view.findViewById(R.id.nameData);
    TextView originDataText=(TextView) view.findViewById(R.id.originData);
    TextView destDataText=(TextView) view.findViewById(R.id.destData);
    Button sendSMS=(Button) view.findViewById(R.id.sendSMS);
    Button callTo=(Button) view.findViewById(R.id.call);
    TableRow tableRow4= (TableRow) view.findViewById(R.id.tableRow40);
    TableRow tableRow5= (TableRow) view.findViewById(R.id.tableRow50);
    TableRow tableRow6= (TableRow) view.findViewById(R.id.tableRow60);
    TableRow tableRow7= (TableRow) view.findViewById(R.id.tableRow70);
    TableRow tableRow8= (TableRow) view.findViewById(R.id.tableRow80);
    TableRow tableRow9= (TableRow) view.findViewById(R.id.tableRow90);
    int visible;
    if (phoneDataText.getVisibility()==View.VISIBLE)
        {
        visible=View.GONE;

        view.setBackgroundResource(android.R.color.transparent);
        }
    else
    {
        visible=View.VISIBLE;
        view.setBackgroundResource(android.R.color.holo_blue_bright);
    }

    phoneDataText.setVisibility(visible);
    commentsDataText.setVisibility(visible);
    nameDataText.setVisibility(visible);
    originDataText.setVisibility(visible);
    destDataText.setVisibility(visible);
    sendSMS.setVisibility(visible);
    callTo.setVisibility(visible);
    tableRow4.setVisibility(visible);
    tableRow5.setVisibility(visible);
    tableRow6.setVisibility(visible);
    tableRow7.setVisibility(visible);
    tableRow8.setVisibility(visible);
    tableRow9.setVisibility(visible);
}

}

0 个答案:

没有答案