データベースからデータをフェッチし、そのコンテンツをテーブル形式に配置しようとしています。オンラインでさまざまなチュートリアルを調べ、コードを次のように構成しましたが、データが表形式でまったく表示されません。TextView を使用すると正常に動作します。これが私のコードです。どこが間違っているかを知ってください。データが表示されないだけで、強制終了は発生しません。
package com.example.callandmessagemanager;
import android.app.Activity;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
public class ViewEncryptedMessages extends Activity{
LinearLayout L;
quer q;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewencryptedmessages);
L=(LinearLayout)findViewById(R.id.LinearLayout1);
TableLayout TL = (TableLayout)findViewById(R.id.TL);
q = new quer(this);
q.open();
Cursor c1;
c1=q.fetchAllTodos();
long c0=1;
int count = c1.getCount();
if(c1!=null)
{
do
{
TextView t;
Cursor c=q.fetchTodo(c0);
String message = c.getString(c.getColumnIndexOrThrow(quer.KEY_MESSAGE));
String number = c.getString(c.getColumnIndexOrThrow(quer.KEY_NUMBER));
TableRow tr = new TableRow(this);
TextView tv1 = new TextView(this);
TextView tv2 = new TextView(this);
createView(tr, tv1, message);
createView(tr, tv2, number);
TL.addView(tr);
/*LayoutParams la=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
t=new TextView(this);
t.setLayoutParams(la);
t.setText(message+" \t"+number);
L.addView(t);*/
c0++;
}while(c0<=c1.getCount());
q.close();
}
else
{
q.close();
Toast.makeText(this, "No Encrypted Messages Received yet", Toast.LENGTH_SHORT).show();
}
}
public void createView(TableRow tr, TextView t, String viewdata) {
t.setText(viewdata);
//adjust the porperties of the textView
t.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
t.setTextColor(Color.DKGRAY);
t.setBackgroundColor(Color.CYAN);
t.setPadding(20, 0, 0, 0);
tr.setPadding(0, 1, 0, 1);
//tr.setBackgroundColor(Color.BLACK);
tr.addView(t); // add TextView to row.
}
}