[英]Android TableView with MSSQL
I am busy with trying to get an array which i get from MSSQL to display in a table view form in my application. 我正忙于尝试获取从MSSQL获取的数组,以在应用程序中以表格视图的形式显示。 I have tried to google it but i cant seem to find an example of this.
我试图用谷歌搜索它,但是我似乎找不到这个例子。 I have tried it but i am running into one small error.
我已经尝试过,但是遇到一个小错误。 I get the following error
Cannot resolve constructor:Simpletabledata adapter[package.mainactivity, package.itemarray]
我收到以下错误
Cannot resolve constructor:Simpletabledata adapter[package.mainactivity, package.itemarray]
Here is my mainactivy.java
class: 这是我的
mainactivy.java
类:
public class MainActivity extends AppCompatActivity {
static String[] spaceProbeHeaders={"Name"};
private ArrayList<ClassListItems> itemArrayList; //List items Array
private MyAppAdapter myAppAdapter; //Array Adapter
final TableView<String[]> tableView = (TableView<String[]>) findViewById(R.id.tableView);
private boolean success = false; // boolean
Connection conn; // Connection Class Initialization
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tableView.setHeaderBackgroundColor(Color.parseColor("#777777"));
tableView.setHeaderAdapter(new SimpleTableHeaderAdapter(this,spaceProbeHeaders));
tableView.setColumnCount(4);
itemArrayList = new ArrayList<ClassListItems>(); // Arraylist Initialization
// Calling Async Task
SyncData orderData = new SyncData();
orderData.execute("");
}
// Async Task has three overrided methods,
private class SyncData extends AsyncTask<String, String, String>
{
String msg = "Internet/DB_Credentials/Windows_FireWall_TurnOn Error, See Android Monitor in the bottom For details!";
ProgressDialog progress;
@Override
protected void onPreExecute() //Starts the progress dailog
{
progress = ProgressDialog.show(MainActivity.this, "Synchronising",
"Tableview Loading! Please Wait...", true);
}
@Override
protected String doInBackground(String... strings) // Connect to the database, write query and add items to array list
{
try
{
ConnectionClass conStr=new ConnectionClass();
conn =conStr.connectionclass();
//Connection Object
if (conn == null)
{
success = false;
}
else {
// Change below query according to your own database.
String query = "SELECT customer_first_name FROM cc_customer";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
if (rs != null) // if resultset not null, I add items to itemArraylist using class created
{
while (rs.next())
{
try {
itemArrayList.add(new ClassListItems(rs.getString("customer_first_name")));
} catch (Exception ex) {
ex.printStackTrace();
}
}
msg = "Found";
success = true;
} else {
msg = "No Data found!";
success = false;
}
}
} catch (Exception e)
{
e.printStackTrace();
Writer writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
msg = writer.toString();
success = false;
}
return msg;
}
@Override
protected void onPostExecute(String msg) // disimissing progress dialoge, showing error and setting up my listview
{
progress.dismiss();
Toast.makeText(MainActivity.this, msg + "", Toast.LENGTH_LONG).show();
if (success == false)
{
}
else {
try {
//myAppAdapter = new MyAppAdapter(itemArrayList, MainActivity.this);
tableView.setDataAdapter(new SimpleTableDataAdapter(MainActivity.this,itemArrayList ));
} catch (Exception ex)
{
}
}
}
}
and here is my classlist.java
file: 这是我的
classlist.java
文件:
public class ClassListItems
{
public String name; //Name
public ClassListItems(String name)
{
this.name = name;
}
public String getName() {
return name;
}
NB: OP is using SortableTableView Library . 注意:OP正在使用SortableTableView Library 。
You need to import the following to solve Cannot resolve constructor:SimpleTableDataAdapter
- 您需要导入以下内容以解决
Cannot resolve constructor:SimpleTableDataAdapter
import de.codecrafters.tableview.toolkit.SimpleTableDataAdapter;
Do you have SimpleTableDataAdapter
class in your project? 您的项目中是否有
SimpleTableDataAdapter
类? It seems it can't find the class so it is not in the same package. 似乎找不到该类,因此它不在同一包中。 If it is in different package, you need to import it.
如果它在其他软件包中,则需要将其导入。 And on a different note, your .java file names should match the class name
另外请注意,您的.java文件名应与类名匹配
And on another different note, have you tested that itemArrayList
is actually populating? 另外,您是否测试了
itemArrayList
实际上正在填充? For Android-MSSQL, here is a tutorial pointer - 对于Android-MSSQL,这是教程指针-
https://parallelcodes.com/connect-android-to-ms-sql-database-2/ https://parallelcodes.com/connect-android-to-ms-sql-database-2/
There are many tutorials if you google it. 有很多教程,如果您谷歌它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.