查看表单包含文本视图,列表视图和按钮,但在调试过程中只显示白色空白表单。
view_dates_e.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/view_e"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="14dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView2" >
</ListView>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Add Expense" />
</RelativeLayout>
ViewExpenseDate.java:
package com.example.expensetracker1;
import com.example.expensetracker1.helper.SchemaHelper;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class ViewExpenseDate extends Activity implements OnClickListener{
Button GoBton;
public void ViewExpDate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_dates_e);//to change
Bundle bundle = getIntent().getExtras();
String date4,cat_a = null,cat_b = null,cat_c = null,cat_d = null,cat_e = null,cat_f=null;
int a1=0,b1=0,c1=0,d1=0,e1=0,f1=0;
SchemaHelper sh = new SchemaHelper(this);
TextView txt1 = (TextView)findViewById(R.id.textView1);
TextView txt2 = (TextView)findViewById(R.id.textView2);
date4 = bundle.getString("Date");
Toast msg2 = Toast.makeText(getApplicationContext(),"Selected Date : \n"+date4,Toast.LENGTH_SHORT);
msg2.show();
txt1.setText("Today's Expenses : " + date4);
Cursor c = sh.getDetails(date4);
while (c.moveToNext()){
int Cat = c.getColumnIndex(DetailsTable.C_ID);
int Amt = c.getColumnIndex(DetailsTable.E_Amt);
int ader = c.getColumnIndex(DetailsTable.O_NAME);
if(Cat==1){
a1 = a1+Amt;
cat_a = "Foods: \n"+a1;
}else if(Cat==2){
b1 = b1+Amt;
cat_b = "Fares: \n"+b1;
}else if(Cat==3){
c1 = c1+Amt;
cat_c = "Bills: \n"+c1;
}else if(Cat==4){
d1 = d1+Amt;
cat_d = "Personal Needs: \n"+d1;
}else if(Cat == 5){
cat_e = "Fares: \n"+e1;
};
cat_f=cat_a+"\n"+cat_b+"\n"+cat_c+"\n"+cat_d+"\n"+cat_e+"\n";
txt2.setText(cat_f);
}
GoBton = (Button)findViewById(R.id.button1);
GoBton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent view_e = new Intent(v.getContext(),Input_Expense.class);
startActivity(view_e);
}
});
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
而且,这是ViewExpenseDate.java之前的活动,
Expense_Calendar.java
package com.example.expensetracker1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.Time;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
public class Expense_Calendar extends Activity implements OnClickListener,OnDateChangedListener{
Button GoBtn;
DatePicker datepick ;
int date1,date2,date3;
Bundle bun = new Bundle();
Time today;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.expense_calendar_layout);
today = new Time(Time.getCurrentTimezone());
today.setToNow();
Toast msg2 = Toast.makeText(getApplicationContext(),"Current Date \n"+(today.month+1)+"/"+today.monthDay+"/"+today.year,Toast.LENGTH_LONG);
msg2.show();
//now.set(2015, 1, 12);
datepick = (DatePicker)findViewById(R.id.datePicker1);
GoBtn = (Button)findViewById(R.id.button1);
GoBtn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
date1 = datepick.getMonth() + 1;
date2 = datepick.getDayOfMonth();
date3 = datepick.getYear();
int now1 = today.month + 1; //d.MONTH;
int now2 = today.monthDay; //d.DATE;
int now3 = today.year; //d.YEAR;
//converting dates into string
String now4 = now1+"/"+now2+"/"+now3;
String date4 = date1+"/"+date2+"/"+date3;
SimpleDateFormat dateFormat= new SimpleDateFormat("MM/dd/yyyy");
Date convDate1 = new Date();
Date convDate2 = new Date();
try {
convDate1 = dateFormat.parse(now4);
convDate2 = dateFormat.parse(date4);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (convDate1.equals(convDate2)){
Intent i = new Intent(v.getContext(),ViewExpenseDate.class);
bun.putString("Date", date4);
i.putExtras(bun);
startActivity(i);
}else if (convDate1.after(convDate2)){
Intent e = new Intent(v.getContext(),ViewExpensePerDate.class);
bun.putString("Date", date4);
e.putExtras(bun); //Pasa ang Date sa Ibang Form
startActivity(e);
}else if ( convDate1.before(convDate2)){
Intent r = new Intent(v.getContext(),ViewReminderDate.class);
bun.putString("Date", date4);
r.putExtras(bun);
startActivity(r);
}
}
});
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
}
}
Expense_Calendar.java的xml文件显示在调试期间显示正常,但在&#34; if(convDate1.equals(convDate2))&#34;条件为true,接下来显示的view_date_e.xml表单应该有一些textview,listview和一个按钮显示,但它只显示一个空白表单。
非常感谢任何帮助