嘿那裏工作與我通過點擊一個按鈕調用活動的應用程序。報告。課堂活動必須在其按鈕點擊事件中打開對話框。 但不幸的是它不顯示對話框。對話框不打開android
下面是代碼:
public class Report extends Activity{
int t_id;
int list1=2,list2=3;
Button btn_day,btn_category,btn_partner,btn_finish;
Context context=this;
SQLiteDatabase db;
SimpleCursorAdapter cursor;
sqliteHelper helper = new sqliteHelper(this);
Cursor c;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.report);
Intent i = getIntent();
t_id=i.getIntExtra("t_id",0);
btn_day=(Button)findViewById(R.id.btn_day);
btn_category=(Button)findViewById(R.id.btn_exp);
btn_partner=(Button)findViewById(R.id.btn_partner);
btn_day.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
db = helper.getReadableDatabase();
c=db.rawQuery("Select date,SUM(ammount) from tbl_expense where c_trip_id=? GROUP BY date",new String[] {Integer.toString(t_id)});
System.out.println("total columns"+c.getColumnCount());
if(c.getCount()!=0)
{
fetch();
}
}
});
});
btn_partner.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
db = helper.getReadableDatabase();
final String MY_QUERY = "SELECT a.user_name, SUM(b.ammount) FROM tbl_usermain a INNER JOIN tbl_expense b ON a.user_id=b.c_u_id WHERE b.c_trip_id=? GROUP BY a.user_name ";
c=db.rawQuery(MY_QUERY, new String[]{Integer.toString(t_id)});
//c=db.rawQuery("Select date,SUM(ammount) from tbl_expense where c_trip_id=? GROUP BY date",new String[] {Integer.toString(t_id)});
System.out.println("total columns"+c.getColumnCount());
if(c.getCount()!=0)
fetch();
}
});
}
private void fetch() {
// TODO Auto-generated method stub
final Dialog dialog = new Dialog(Report.this);
dialog.setContentView(R.layout.reportlist);
LinearLayout reportlistview=(LinearLayout)dialog.findViewById(R.id.reportlayout);
dialog.setTitle("Report");
dialog.show();
ArrayList<HashMap> expense_by_user = new ArrayList<HashMap>();
c.moveToFirst();
for(int j=1;j<=c.getCount();j++)
{
HashMap temp = new HashMap();
temp.put(FIRST_COLUMN,j);
temp.put(SECOND_COLUMN, c.getString(0));
temp.put(THIRD_COLUMN, c.getInt(1));
expense_by_user.add(temp);
c.moveToNext();
}
c.close();
db.close();
/*SET THE ADAPTER TO LISTVIEW*/
ListView list=new ListView(Report.this);
list.setId(list2);
listviewAdapter adapter = new listviewAdapter(Report.this, expense_by_user);
list.setAdapter(adapter);
reportlistview.addView(list);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
int viewId = this.getCurrentFocus().getId();
outState.putInt("hasFocus", viewId);
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
int viewId = savedInstanceState.getInt("hasFocus");
View view = findViewById(viewId);
view.requestFocus();
}
}
logcat的觀點:
01-06 12:03:48.603: INFO/ActivityManager(61): Starting: Intent { cmp=com.NRP.MainPackage/.Report (has extras) } from pid 918
01-06 12:03:49.873: INFO/ActivityManager(61): Displayed com.NRP.MainPackage/.Report: +1s160ms
01-06 12:03:50.154: DEBUG/dalvikvm(61): GC_CONCURRENT freed 968K, 46% free 4369K/8071K, external 2269K/3469K, paused 24ms+13ms
01-06 12:03:52.294: INFO/System.out(918): total columns2
01-06 12:04:05.676: INFO/System.out(918): total columns2
01-06 12:05:17.223: VERBOSE/BackupManagerService(61): Backup requested but nothing pending
01-06 12:06:02.463: DEBUG/SntpClient(61): request time failed: java.net.SocketException: Address family not supported by protocol
與解決它:
c.moveToFirst();
if(c.getColumnCount()!=0)
fetch();
}
請發佈logcat錯誤。 –
確保在點擊按鈕時調用fatch()。 –
其**取**,而不是* fatch * :) –