我的第二个活动是FragmentActivity,我正在放置一个片段start_View。在片段start_View的onCreateView函数中,我在tablelayout中动态地放置了近100行。根据我的准备时间,这就是为什么空白屏幕即将到来,请建议。
我的onCreateView函数代码,我在调用ShowDataTask。此代码存在于start_view片段中。这是从第二个活动中调用的。应用程序启动后。
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
//activity=getActivity();
View view=null;
Cursor cr=null;
view=inflater.inflate( R.layout.activity_start__view, container, false);
new ShowDataTask(this,view).execute(null,null,null);
return view;
}
它的showDataTask代码,我在调用showDataInTable函数。
class ShowDataTask extends AsyncTask<String, String, String> {
Start_View start_View;
View view;
Context context;
SimpleDateFormat smf=new SimpleDateFormat("dd-MM-yyyy",Locale.US);
ProgressDialog dialog;
String select_query="select Date from SmsRead";
public ShowDataTask(Start_View stv,View v) {
view=v;
start_View=stv;
context=start_View.getActivity();
}
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(context);
dialog.setCancelable(false);
dialog.getWindow().setGravity(Gravity.TOP);
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
wmlp.y = 100;
dialog.getWindow().setAttributes(wmlp);
//dialog.setProgressStyle(ProgressDialog.THEME_HOLO_DARK);
dialog.setIndeterminate(true);
dialog.setTitle("Prepating View");
dialog.setMessage("Wait For a While...");
dialog.show();
}
@Override
protected String doInBackground(String... date) {
try{
start_View.showDataInTable(view);
}catch(Exception ex){
//Log.e("<<<<path>>>>>>", getDatabasePath("ReadSms.db").toString());
ex.printStackTrace();
Log.e("Exception", ex.toString());
}
return "dd";
}
@Override
protected void onPostExecute(String result) {
// dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
//progressBar.setVisibility(View.INVISIBLE);
dialog.dismiss();
}
}
及其ShowDataInTable代码,我正在动态地准备Tablelayout。
public void showDataInTable(View view){
Cursor cr=null;
db=new Database(getActivity());
SQLiteDatabase db1 = db.getWritableDatabase();
try{
TextView txt=(TextView)view.findViewById(R.id.testtext);
TableLayout ll=(TableLayout) view.findViewById(R.id.tablelayout1);
TableRow trow;
TextView tv1;
TextView tv2;
TextView tv3;
TextView tv4;
TextView tv;
String st="select * from MainTableRead order by Date desc";
String Previous_month="";
cr=db1.rawQuery(st,null);
String date1="";
if(cr.moveToFirst()){
String month="";
do{
String address=cr.getString(0);
String Received=cr.getString(2);
String body=cr.getString(3);
long milliseconds=Long.valueOf(Received);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliseconds);
date1= smf.format(calendar.getTime());
String date[]=date1.split("-");
month=getMonth(date[1]);
String year=date[2];
String amt="";String bal="";
String Result= Parse.parseData(body,address);
String amt_Bal[]=Result.split("#");
if(amt_Bal.length>1){
amt=amt_Bal[0];bal=amt_Bal[1];
}
if(amt!=null && bal!=null && !amt.equals("") && !bal.equals("")){
if(!Previous_month.equalsIgnoreCase(month)){
if(!Previous_month.equals("") && (month_credit!=0 || month_debit!=0)){
//credit debit row
TableRow trow3=new TableRow(getActivity());
trow3.setBackgroundResource(R.color.pink);
TextView tv6=new TextView(getActivity());
TextView tv7=new TextView(getActivity());
tv6.setText("C: "+month_credit);tv7.setText("D :"+month_debit);
trow3.addView(tv6);trow3.addView(tv7);
ll.addView(trow3);
}
TableRow trow2=new TableRow(getActivity());
trow2.setClickable(true);
trow2.setOnLongClickListener(this);
trow2.setBackgroundResource(R.color.yellow);
month_credit=0;month_debit=0;
TextView tv5=new TextView(getActivity());
TextView tv6=new TextView(getActivity());
TextView tv7=new TextView(getActivity());
TextView tv8=new TextView(getActivity());
TextView tv9=new TextView(getActivity());
tv5.setPadding(6,2,6,2);tv6.setPadding(6,2,6,2);tv7.setPadding(6,2,6,2);tv8.setPadding(6,2,6,2);
tv5.setText(""+month+" "+year); tv6.setText(""); tv7.setText(""); tv8.setText("");tv9.setText("");
trow2.addView(tv5); trow2.addView(tv6); trow2.addView(tv7); trow2.addView(tv8);trow2.addView(tv9);
ll.addView(trow2);
trow=new TableRow(getActivity());
trow.setClickable(true);
trow.setMinimumWidth(10);
trow.setBackgroundResource(R.color.yellow);
tv1=new TextView(getActivity());
tv2=new TextView(getActivity());
tv3=new TextView(getActivity());
tv4=new TextView(getActivity());
TextView tv10=new TextView(getActivity());
tv1.setText("Address"); tv2.setText(" Balance"); tv3.setText(" Amount"); tv4.setText(" Date");tv10.setText("");
trow.addView(tv1); trow.addView(tv2); trow.addView(tv3);trow.addView(tv4);
ll.addView(trow);
Previous_month=month;
}
trow=new TableRow(getActivity());
trow.setClickable(true);
trow.setId(30);
trow.setBackgroundResource(R.color.pink);
tv1=new TextView(getActivity());tv2=new TextView(getActivity());tv3=new TextView(getActivity());
tv4=new TextView(getActivity());tv=new TextView(getActivity());tv.setWidth(0);tv.setHeight(0);
tv1.setPadding(6,2,6,2);tv2.setPadding(6,2,6,2);tv3.setPadding(6,2,6,2);tv4.setPadding(6,2,6,2);
tv1.setText(""+address);tv2.setText(" "+amt);tv3.setText(" "+bal);tv4.setText(" "+date1);
tv.setText(""+body);tv.setVisibility(View.INVISIBLE);
trow.addView(tv1); trow.addView(tv2); trow.addView(tv3);trow.addView(tv4);trow.addView(tv);
amt=amt.trim().replace(",","");
if(amt.contains("-")){
month_debit=month_debit+Double.valueOf(amt);
month_debit=Math.floor(month_debit*100)/100;
Log.e("month_debit", ""+month_debit);
}
else if(amt.contains("+")){
month_credit=month_credit+Double.valueOf(amt);
month_credit=Math.floor(month_credit*100)/100;
}
trow.setOnClickListener(this);
trow.setOnLongClickListener(this);
ll.addView(trow);
}
}while(cr.moveToNext());
if(month_credit!=0 || month_debit!=0){
TableRow trow3=new TableRow(getActivity());TableRow trow4=new TableRow(getActivity());
trow4.setPadding(0, 2, 2, 50);
trow3.setBackgroundResource(R.color.pink);
TextView tv6=new TextView(getActivity());TextView tv7=new TextView(getActivity());
tv6.setText("C: "+month_credit);tv7.setText("D :"+month_debit);
tv6.setBackgroundResource(R.color.pink);tv7.setBackgroundResource(R.color.pink);
trow3.addView(tv6);trow3.addView(tv7);
ll.addView(trow3);ll.addView(trow4);
ll.getChildAt(0);
}
}
cr.close();
db1.close();
db.close();
Log.d("<<<<<<<sms Read>>>>>>>>>","fffffff");
}catch(Exception ex){
Log.e("Exception inside stasrt view in row creation", ex.toString());
cr.close();
db.close();
db1.close();
ex.printStackTrace();
}
}