我创建的listView
在每个项目中都有seekBar
和textView
。我是否需要根据textView
移动更新seekBar
。ListView
行是根据数据库表中的行数创建的。如何实现此目的?。我的代码如下
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);
}
}
我应该为活动代码做些什么?你的建议对我很有价值。
答案 0 :(得分:1)
使用BaseAdapter或ArrayAdapter创建自定义列表适配器。 将适配器连接到ListView 在适配器的getView()方法中获取seekbar的引用并将监听器设置为seekbar,如下所示:
timestamp is value like 1432527031.