Skip to content

Instantly share code, notes, and snippets.

@goldeneggg
Created September 12, 2011 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goldeneggg/1211314 to your computer and use it in GitHub Desktop.
Save goldeneggg/1211314 to your computer and use it in GitHub Desktop.
DevQuiz 2011 Androidの解答(Activity&layout xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="@+id/disp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="disp" />
<TextView
android:id="@+id/code"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
</LinearLayout>
package devquiz11.aidl;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.apps.gddquiz.IQuizService;
public class MainActivity extends Activity {
Button btn = null;
TextView code = null;
IQuizService remoteService;
private ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
remoteService = IQuizService.Stub.asInterface(service);
}
@Override
public void onServiceDisconnected(ComponentName name) {
// クリア
remoteService = null;
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bindService(new Intent(IQuizService.class.getName()), conn, BIND_AUTO_CREATE);
code = (TextView)findViewById(R.id.code);
btn = (Button)findViewById(R.id.disp);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
code.setText(remoteService.getCode());
} catch (RemoteException e) {
code.setText("Oops!!");
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment