저는 학교용 앱을 만들려고합니다. 버튼을 누를 때마다 팝업 상자를 만들고 싶습니다. 라인 25나는이 코드를 Android에서 구현하려고합니다.이 멍청한 놈이
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button showPopUp = (Button) findViewById(R.id.button);
showPopUp.OnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
showSimplePopUp();
}
});
}
private void showSimplePopUp() {
AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
helpBuilder.setTitle("Opening Line");
helpBuilder.setMessage("You popped my jingles up");
helpBuilder.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do nothing but close the dialog
}
});
// Remember, create doesn't show the dialog
AlertDialog helpDialog = helpBuilder.create();
helpDialog.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Logcat을 게시하시기 바랍니다. – Lal
이것은 분명히 중복 질문입니다 : http://stackoverflow.com/q/22720108/2777098 –