安卓提示框代码写了但是没显示 AlertDialog.Builder builder 100

packagecom.coco.view;importjava.util.ArrayList;importjava.util.List;importorg.apache.... package com.coco.view;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;

import com.coco.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class UserSearchByCountActivity extends Activity {

private EditText etUsername = null;
private AlertDialog.Builder builder;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.user_findfriends_byaccount);
etUsername =(EditText)findViewById(R.id.user_findfriends_byaccount_et_count);
builder= new Builder(UserSearchByCountActivity.this);
}
public void onSearch(View view) {
if (etUsername == null) {
AlertDialog.Builder builder = new Builder(UserSearchByCountActivity.this);
builder.setTitle("确认" ) ;
builder.setMessage("账号不能为空噢~" ) ;
builder.setPositiveButton("是" , null );
builder.show();

}
else {
Intent intent = new Intent();
intent.setClass(UserSearchByCountActivity.this, UserListActivity.class);
intent.putExtra("username", etUsername.getText().toString());
intent.putExtra("Type", 3);
startActivity(intent);

}

}
public void onBack(View view) {

Intent intent = new Intent();
intent.setClass(this, UserFindFriendActivity.class);
startActivity(intent);
}

}

为何写了当输入为空时提示,但输入为空时没任何提示
展开
 我来答
匿名用户
2015-04-14
展开全部
public class MyDialog extends Dialog {
private int FLAG_DISMISS = 1;
private boolean flag = true;

public MyDialog(Context context) {
super(context);
setTitle("自动消失对话框测试!");
}

@Override
public void show() {
super.show();
mThread.start();
}

@Override
public void dismiss() {
super.dismiss();
flag = false;
}

private Thread mThread = new Thread(){
@Override
public void run() {
super.run();
while(flag){
try {
Thread.sleep(2000);
Message msg = mHandler.obtainMessage();
msg.what = FLAG_DISMISS;
mHandler.sendMessage(msg);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};

private Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(msg.what == FLAG_DISMISS)
dismiss();
}

};

}

LZ 筒子,AlertDialog都被框死用来做警告用的,不好操作。想实现自己的对话框还是继承Dialog然后DIY更好,选择也多得多了。我这个自定义的Dialog就是显示了2s然后消失的,测试过没问题。实现起来也相当之简单,抛砖引玉,期待更好的方法。
追问
那我要用在我那里该怎么写
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式