我正在尝试将数据库中的数据插入表视图布局中。我有一个名为getData
的文件,该文件访问我的数据库并将所有信息存储到一个数组中,您可以在下面找到它:
public class GetValence {
Connection connect;
String ConnectionResult = "";
Boolean isSuccess = false;
public List<Map<String,String>> doInBackground() {
List<Map<String, String>> data = null;
data = new ArrayList<Map<String, String>>();
try
{
ConnectionHelper conStr=new ConnectionHelper();
connect =conStr.connectionclass(); // Connect to database
if (connect == null)
{
ConnectionResult = "Check Your Internet Access!";
}
else
{
// Change below query according to your own database.
String query = "select * from cc_valence";
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()){
Map<String,String> datanum=new HashMap<String,String>();
datanum.put("NAME",rs.getString("VALENCE_NAME"));
datanum.put("PRICE",rs.getString("VALENCE_UNIT_PRICE"));
datanum.put("RANGE",rs.getString("VALENCE_RANGE"));
datanum.put("SUPPLIER",rs.getString("VALENCE_SUPPLIER"));
datanum.put("SIZE",rs.getString("VALENCE_SIZE"));
data.add(datanum);
}
现在我需要将这些数据插入我的Table_test.java
文件中,以便在我的表格视图中显示,您可以在下面找到它:
public class TableTest extends AppCompatActivity {
static String[] spaceProbeHeaders={"Name","Price","Range","Supplier","Size"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_table_test);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final TableView<String[]> tableView = (TableView<String[]>) findViewById(R.id.tableView);
tableView.setHeaderBackgroundColor(Color.parseColor("#777777"));
tableView.setHeaderAdapter(new SimpleTableHeaderAdapter(this,spaceProbeHeaders));
tableView.setColumnCount(5);
List<Map<String,String>> MyData = null;
GetValence mydata =new GetValence();
MyData= mydata.doInBackground();
String[] fromwhere = { "NAME","PRICE","RANGE","SUPPLIER","SIZE" };
tableView.setDataAdapter(new SimpleTableDataAdapter(TableTest.this, fromwhere));
}
但是我得到Cannot resolve constructor SimpleTabledataAdapter