① android中如何動態創建數據表
在布局中加入表格
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/table1">
</TableLayout>
之後再 MainActivity 中寫入動態添加的代碼
public void click(View v) {
if(row.getText().length()>0&&column.getText().length()>0){
//把輸入的行和列轉為整形
int row_int=Integer.parseInt(row.getText().toString());
int col_int=Integer.parseInt(column.getText().toString());
//獲取控制項tableLayout
tableLayout = (TableLayout)findViewById(R.id.table1);
//清除表格所有行
tableLayout.removeAllViews();
//全部列自動填充空白處
tableLayout.setStretchAllColumns(true);
//生成X行,Y列的表格
for(int i=1;i<=row_int;i++)
{
TableRow tableRow=new TableRow(MainActivity.this);
for(int j=1;j<=col_int;j++)
{
//tv用於顯示
TextView tv=new TextView(MainActivity.this);
//Button bt=new Button(MainActivity.this);
tv.setText("("+i+","+j+")");
tableRow.addView(tv);
}
//新建的TableRow添加到TableLayout
tableLayout.addView(tableRow, new TableLayout.LayoutParams(MP, WC,1));
}
}else{
Toast.makeText(MainActivity.this,"請輸入數值",1).show();
}
}
② 如何將Android資料庫中表格的某一列在下拉列表中顯示
請參考SDK下APIDemo例子,裡面有詳細的介紹,路徑platforms/android-4(我的是1.6的)/samples/ApiDemos
,打開應用操作步驟如下Views-->List,裡面有很多中列表,你自己選擇;
關於新建item,如果你要實現自己的樣式,可以自定Adapter;你提問中android.R.layout.simple_spinner_item和別人的item是一個作用,就是列表中每一行的樣式,有什麼問題再hi我
③ 安卓怎麼編寫圖形化界面(比如圖表)展示資料庫數據
這個圖形化界面是在layout布局文件中(.xml)編寫代碼,也可以將圖表以圖片形式放入UI文件里。資料庫的數據可以採取調用方法顯示在圖表相應id位置的。因為不清楚你具體要求是什麼,所以只能大概給你這么說一下
④ 安卓手機看錶格數據不顯示小數點後面數據怎麼回事
摘要 親,您好,根據您的問題,答主這邊查詢到的信息是:因為沒設置好。
⑤ 安卓開發 如何拿到數據列表 把size顯示到界面上
Android中載入list列表數據主要是通過Adapter實現,可用顯示列表的控制項如下: Listview GridView ExpandListview 顯示具體的數據需要通過Adapter實現,Android目前有4種Adapter: ArrayAdapter SimpleAdapter SimpleCursorAdapter BaseAdapter ( 自定義Adapter) 具體操作步驟 ( 以自定義Adapter為例): 在xml中定義Listview布局 在代碼中通過ID找到Listview控制項 構建Adapter對象,新建一個類繼承自BaseAdapter,重寫它的四個方法,具體如下代碼 構造好適配器後設置Listview的adapter對象為新建的適配器,界面即可顯示數據 在數據變動的地方,只需要調用adapter的notifyDataSetChanged方法即可刷新界面 package com.beryl.gougou; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import java.util.List; /** * Created by yt on 16/11/14. */ public class MyAdapter extends BaseAdapter { private List<String> datalist; private LayoutInflater inflater; public MyAdapter(Context context ,List<String> datalist){ this.datalist = datalist; inflater = LayoutInflater.from(context); } @Override public int getCount() { return datalist.size(); } @Override public Object getItem(int position) { return datalist.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { //此處參考網上的view緩存機制,示例demo不多說明 return null; } }
⑥ android sqlite查詢兩張表中的數據 如何顯示出來
這是我剛寫的簡單例子,從聯系人里讀取數據,填入spinner,希望有用~ import android.app.Activity; import android.database.Cursor; import android.os.Bundle; import android.provider.ContactsContract.CommonDataKinds.StructuredName; import android.provider.ContactsContract.Data; import android.widget.SimpleCursorAdapter; import android.widget.Spinner; public class temp extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Cursor c = managedQuery(Data.CONTENT_URI, new String[]{ Data._ID, Data.DATA1 }, Data.MIMETYPE + "='" + StructuredName.CONTENT_ITEM_TYPE + "'", null, null); SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_dropdown_item_1line, c, new String[]{ Data.DATA1 }, new int[]{ android.R.id.text1 }); Spinner s1 = (Spinner) findViewById(R.id.Spinner01); s1.setAdapter(adapter); } }
⑦ Android中GridView顯示表格數據實現了手勢縮放,但垂直滾動條不能用了,求指教
會不會是介面沖突了啊? 就是說在OnTouchListener中重寫了手往下滑動的代碼,然後在OnGestureListener中也重寫了手往下滑的代碼,兩個又不一樣,然後系統不知道聽哪個好啊?你可以網路搜索研究下OnTouchListener和OnGestureListener之間的關系,我也研究下,研究明白了互相通知下哈,互相學習~呵呵
可以把源碼發我一份研究下嗎?我自己試著在GridView上家手勢(Gesture),似乎有點難度
⑧ 如何用安卓編寫類Excel的表格並填充數據
前段時間應運營需求要求做一個小Demo用來顯示數據,在這個過程中,我學會了用代碼來做出類似於Excel表格的顯示效果,下面就和大家一起分享。
要做成表格形式的布局,很容易讓我們想到表格布局,所以先要新建一個layout,在這個layout中我們放入兩個TableLayout,其中一個是用來顯示表格中的標題,而另一個TableLayout用來顯示數據,考慮到可能顯示的數據較多,所以外麵包上一層ScrollView。主要代碼如下:
[html] view plain
<TableLayout
android:id="@+id/tablelayout_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffdedcd2"
android:stretchColumns="*" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/tablelayout_title"
android:orientation="vertical">
<TableLayout
android:id="@+id/tablelayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffdedcd2"
android:stretchColumns="*" />
</ScrollView>
寫好布局文件後,我們開始要填充數據了,也就是我代碼中寫到的addWidget()方法。數據的話我是造的json類型的假數據,並且新建對象類進行解析,這個就不多說了。先看主要的填充數據的代碼。首先是表格的標題,也就是我們通常看到的表格最上方那一欄。主要代碼如下:
for (int j = 0; j < 1; j++) {
TableRow localTableRow1 = new TableRow(this);
localTableRow1.setBackgroundColor(getResources().getColor(R.color.realtime_table_bg));
for (int k = 0; k < this.column; k++) {
TextView localTextView1 = new TextView(this);
localTextView1.setWidth(this.viewWidth);
localTextView1.setBackgroundResource(R.drawable.table_shape_title);
localTextView1.setGravity(17);
localTextView1.setTextSize(2, 16);
localTextView1.setTextColor(getResources().getColor(R.color.white));
localTextView1.getPaint().setFakeBoldText(true);
localTextView1.setSingleLine();
switch (k) {
default:
break;
case 0:
localTextView1.setText("A");
localTableRow1.addView(localTextView1);
break;
case 1:
localTextView1.setText("B");
localTableRow1.addView(localTextView1);
break;
case 2:
localTextView1.setText("C");
localTableRow1.addView(localTextView1);
break;
case 3:
localTextView1.setText("D");
localTableRow1.addView(localTextView1);
break;
case 4:
localTextView1.setText("E");
localTableRow1.addView(localTextView1);
break;
case 5:
localTextView1.setText("F");
localTableRow1.addView(localTextView1);
break;
case 6:
localTextView1.setText("G");
localTableRow1.addView(localTextView1);
break;
case 7:
localTextView1.setText("H");
localTableRow1.addView(localTextView1);
}
}
this.tb_title.addView(localTableRow1, new TableLayout.LayoutParams(-1, -2));
}
我們用兩個for循環來實現這個數據的填充,最外層for循環之所以判斷「j<1」,是因為我們這里只要一行就夠了。我們在這里新建一個TabRow,然後再在這一行中添加列。里層的這個for循環中的column就是我們的列數,這里我們用A~H表達我們的列標題名稱,通過一個for循環每次新建一個新的TextView,然後判斷是第幾列,根據位置依次加入我們的列名稱。最後在tb_title,也就是我們標題對應的這個TableLayout中添加這些view。
同樣的,下面的表格布局也是同樣的用兩個for循環來實現,只是最外層循環我們是要根據伺服器傳過來的列表大小來決定了。
因為我們手機通常是書評,可能導致顯示不全或不便觀看的問題,所以在setContentView()方法之前我加了一個判斷,保證一進入這個頁面就會顯示為橫屏:
if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
不過運行之後報錯,後來發現是因為這個activity沒有設置屏幕顯示方向導致的,最後在清單文件裡面加上下面這句代碼就可以了。android:screenOrientation="sensorLandscape"
表格布局的實現和運用就介紹到這里了,demo下載地址:http://download.csdn.net/detail/shan286/9475782
⑨ 如何在Android上將現有的數據,以圖表的形式展現在手機上。
主要思路是:
1. 把資料庫分解成幾個asset文件。
2. 當需要打開資料庫時,如果資料庫不存在,就把那幾個asset文件重新合並成一個資料庫文件。
3. 如果資料庫的版本改變了,就在onUpgrade()方法中把資料庫文件刪除掉。
下面是代碼:
//資料庫的預設路徑
private static finalString DB_PATH = "/data/data/com.mypackage.myapp/databases/";
private static finalString DB_NAME = "mydb.db";
private static finalint DB_VERSION = 2;
private static finalString DB_SPLIT_NAME = "mydb.db.00";
private static finalint DB_SPLIT_COUNT = 3;
private SQLiteDatabasem_database;
private final Contextm_context;
/**
* Constructor
*保存傳進來的context參數以用來訪問應用的asset和資源文件。
* @param context
*/
public MyDB(Contextcontext) {
super(context, DB_NAME, null, DB_VERSION);
this.m_context = context;
}
public static MyDBopenDatabaseReadOnly(Context context) {
MyDB db = new MyDB(context);
try {
db.createDataBase();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
db.openDataBase(SQLiteDatabase.OPEN_READONLY);
return db;
}
public static MyDBopenDatabaseReadWrite(Context context) {
MyDB db = new MyDB(context);
try {
db.createDataBase();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
db.openDataBase(SQLiteDatabase.OPEN_READWRITE);
return db;
}
/**
*創建一個空資料庫,用來存儲你已有的資料庫。
*/
public voidcreateDataBase() throws IOException{
boolean dbExist =checkDataBase();
if (dbExist) {
/*
**如果你的資料庫的版本改變了,調用這個方法確保在onUpgrade()被調用時
**傳進去的是可寫的資料庫。
⑩ android smarttable如何實現數據全部顯示使用ScrollView拖動
1、SDI程序;
2、繼承ScrollView類,派生幾個不同的view;
3、繼承SplitterWnd類,將SDI分割成不同的部分;
4、在每個view(從ScrollView類派生而來的)上會有不同的東西要顯示,主要是一些控制項(EditBox、ComboBox、CheckBtn、Button等)。
當前狀態:
1、SDI分割已完成;
2、每個分割的部分上也生成了view(從ScrollView類派生而來的);
4、每個view上也動態(請注意,每個控制項都是動態生成的,因為控制項數量、名稱、類型都會變)生成了各個控制項。
所遇問題:
1、現在我的view上由於程序啟動時的大小的原因,只能顯示10個控制項,再多的控制項都顯示不出來了;
2、若多餘10個,更多的控制項會從第一個控制項的位置重新生成,這樣就形成了覆蓋;
3、當前view所見范圍外的界面都顯示不出來,拖動滾動條後出現的是殘影。
希望效果:
每個view上能顯示10多個控制項,控制項都是沿著Y方向一個一個排列下去,會超出當前view所見范圍,但是通過拖動滾動條可以都看到並操作。