내 onCreate 메소드에서 특정 유형의 객체 인 을 초기화하여 채울 간단한 테이블 레이아웃이 있습니다. 먼저이 떨어져 내가 가지고있는 레이아웃입니다활동의 테이블 데이터 설정 -이 접근 방식은 작동합니까
jobs_table.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@+id/Jobs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow android:id="@+id/JobRow" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/JobID" android:layout_column="1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
<TextView android:id="@+id/JobStatus" android:layout_column="2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
<TextView android:id="@+id/Customer" android:layout_column="3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
<TextView android:id="@+id/Department" android:layout_column="4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
<TextView android:id="@+id/DocType" android:layout_column="5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView>
</TableRow>
</TableLayout>
그리고 테이블의 데이터가로드됩니다 이제
package com.producermobile;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TableLayout;
import com.producermobile.jobs.ProducerJobRows;
public class JobRowsActivity extends Activity {
private BatchingJobRows jobRows;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.jobs_table);
jobRows = new BatchingJobRows(this);
}
}
내 jobRows를 만들 때 아이디어가 될 것입니다 활동 BatchingJobRows 객체는 내 활동에 사용할 수 있어야합니다. 나는 컨셉이 옳은지 확신 할 수 없기 때문에 (이것은 내가 테이블에서 행을 추가하는 while 루프이다) mo에서 이것을 확인하는 방법이 없다.
어쨌든 여기서 BatchingJobRows의 단순화 된 버전이 있습니다.
package com.producermobile.jobs;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import com.producermobile.R;
public class BatchingJobRows {
private TableLayout table;
private View tableView;
private Context context;
private HashMap<String,ArrayList<String>> jobs;
private ArrayList<String> jobsVals;
public BatchingJobRows(Context context) {
this.context = context;
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
tableView = inflater.inflate(R.layout.jobs_table, null);
table = (TableLayout) tableView.findViewById(R.id.Jobs);
jobVals = new ArrayList<String>();
jobVals.add("HELD");
jobVals.add("DELL");
jobVals.add("PRINT");
jobVals.add("STATEMENT");
jobs = new HashMap<String,ArrayList<String>>();
jobs.put("",jobVals);
jobs.put("123456",jobVals);
this.setRows();
}
public void setRows() {
Iterator<String> keys = jobs.keySet().iterator();
while(keys.hasNext()) {
//Init Objects
TableRow row = (TableRow) TableView.findViewById(R.id.JobRow);
TextView jobid = (TextView) tableView.findViewById(R.id.JobID);
TextView jobstatus = (TextView) tableView.findViewById(R.id.JobStatus);
TextView customer = (TextView) tableView.findViewById(R.id.Customer);
TextView department = (TextView) tableView.findViewById(R.id.Department);
TextView doctype = (TextView) tableView.findViewById(R.id.DocType);
String key = keys.next();
jobid.setText(key);
jobstatus.setText(jobs.get(key).get(0));
customer.setText(jobs.get(key).get(1));
department.setText(jobs.get(key).get(2));
doctype.setText(jobs.get(key).get(3));
row.addView(jobid);
row.addView(jobstatus);
row.addView(customer);
row.addView(department);
row.addView(doctype);
table.addView(row);
}
}
}
나는 정말 불행히도 테이블이 될 필요가있다. – PDStat
ok, 그러나 listview의 각 행에 대한 선형 레이아웃을 반환 할 수없는 몇 가지 이유가 무엇입니까? 그건 맞지 않을까요? – Androider
조금 더 살펴 봤는데 이제는 내 솔루션이 http://united-coders.com/phillip-steffensen/android-dealing-with-listactivities-customized-listadapters-and-custom-designed-0에 기반을두고 있습니다. , nudge에 감사드립니다. – PDStat