Android 搜索栏在列表视图中更新文本视图

Android seekbar update text view in list view

我创建了一个 listView,每个项目都有 seekBartextView。我是否需要根据 seekBar 运动更新 textViewListView 行是根据数据库中的行数创建的 table.How 我可以实现吗?我的代码如下

activity_list_criteria.xml

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="35dp">

    //Label criteria
    <TextView
        android:id="@+id/txtViewCriteria"
        android:textSize="20sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Criteria      : " />

    //Label criteria from db
    <TextView
        android:id="@+id/criteriaName"
        android:textSize="20sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:text="Criteria" />

    <TextView
        android:layout_width="180dp"
        android:layout_height="fill_parent" />


</LinearLayout>

//SeekBar layout
<SeekBar
    android:id="@+id/sbBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:progress="0"
    android:max="5"
    android:paddingTop="20dp" />

//TextViews for SeekBarlegend
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/tvLabel1"
        android:paddingLeft="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="0" />

    <TextView
        android:id="@+id/tvLabel3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:paddingRight="10dp"
        android:text="5" />

</RelativeLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="35dp">

    //Label weightage
    <TextView
        android:id="@+id/txtViewWeightage"
        android:textSize="20sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Weightage: "/>

    //Label weightage from db
    <TextView
        android:id="@+id/criteriaWeightage"
        android:textSize="20sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/stuMatric"
        android:layout_toRightOf="@+id/textView2"
        android:text="Weightage" />

    <TextView
        android:id="@+id/txtView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="0" />

</LinearLayout>

activity_display_assessment.xml

//Title Layout
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="60dp"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="60dp"
        android:background="@drawable/orangehome"
        android:orientation="horizontal">

        <TextView
            android:layout_width="110dp"
            android:layout_height="fill_parent" />

        <TextView
            android:layout_width="170dp"
            android:text="Evaluate"
            android:layout_gravity="center_horizontal"
            android:gravity="center"
            android:textColor="#FFFFFF"
            android:textSize="30sp"
            android:layout_height="60dp" />

        <TextView
            android:layout_width="50dp"
            android:layout_height="fill_parent" />

        <Button
            android:id="@+id/btnLogout"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center_vertical"
            android:background="@drawable/logout"/>

    </LinearLayout>

</LinearLayout>

//Criteria layout
<TextView
    android:id="@+id/txtViewSubject"
    android:paddingTop="10dp"
    android:layout_gravity="center_horizontal"
    android:gravity="center"
    android:layout_width="300dp"
    android:layout_height="60dp"
    android:textSize="18sp"
    android:textColor="#000000"
    android:text="Criteria"/>

//List view for criteria
<ListView
    android:id="@+id/criteriaListView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

DisplayAssessmentActivity.java

public class DisplayAssessmentActivity extends Activity {

    ListDatabaseHandler listCriteria;
    private SimpleCursorAdapter dataAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_assessment);

    //Open connection and get instance from database
    listCriteria = new ListDatabaseHandler(this);
    listCriteria.open();

    //Delete all data
    listCriteria.deleteAllCriteria();

    //Add data
    listCriteria.insertSomeCriteria();

    //Retrieve data from database and display in list view
    displayCriteriaListView();


}

private void displayCriteriaListView() {

    Cursor cursor = listCriteria.fetchAllCriteria();

    // The desired columns to be bound
    String[] columns = new String[] {
            ListDatabaseHandler.KEY_CRITERIANAME,

    };

    // the XML defined views which the data will be bound to
    int[] to = new int[] {
            R.id.criteriaName,
    };

    // create the adapter using the cursor pointing to the desired data
    //as well as the layout information
    dataAdapter = new SimpleCursorAdapter(
            this, R.layout.activity_list_criteria,
            cursor,
            columns,
            to,
            0);

    ListView listView = (ListView) findViewById(R.id.criteriaListView);
    // Assign adapter to ListView
    listView.setAdapter(dataAdapter);

    //Action when click on the item
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> listView, View view,
                                int position, long id) {
            // Get the cursor, positioned to the corresponding row in the result set
            Cursor cursor = (Cursor) listView.getItemAtPosition(position);

            String criteria = cursor.getString(cursor.getColumnIndexOrThrow("criteria_name"));

            String weightage =
                    cursor.getString(cursor.getColumnIndexOrThrow("criteria_weightage"));

            //Toast.makeText(getApplicationContext(),
            //subjectName, Toast.LENGTH_SHORT).show();


            Intent intentResult = new Intent(getApplicationContext(), ResultActivity.class);

            startActivity(intentResult);

        }
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_display_assessment, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

activity代码我应该怎么办?你的建议对我很有价值。

使用 BaseAdapter 或 ArrayAdapter 创建自定义列表适配器。 将适配器附加到 ListView 在适配器的 getView() 方法中获取 seekbar 的引用并将侦听器设置为 seekbar,如下所示:

final TextView text=convertView.findViewById(R.id.textview);     
final SeekBar seekbar=(SeekBar) convertView.findViewById(R.id.seekBar1);     
sk.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {       

@Override       
public void onStopTrackingTouch(SeekBar seekBar) {      
    // TODO Auto-generated method stub      
}       

@Override       
public void onStartTrackingTouch(SeekBar seekBar) {     
    // TODO Auto-generated method stub      
}       

@Override       
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {     
    // TODO Auto-generated method stub      

    text.setText(progress);


}       
});