- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
public abstract class SomeActivity extends Activity implements SomeEventListener {
private volatile Integer someEventAnswer;
@Override
public Integer onSomeEvent(final Collection<String> someData) {
final CountDownLatch latch = new CountDownLatch(1);
runOnUiThread(new Runnable() {
@Override
public void run() {
showSomeDialog(someData, latch);
}
});
try {
latch.await();
} catch (InterruptedException ignored) {
}
Integer ret = someEventAnswer;
someEventAnswer = null;
return ret;
}
private void showSomeDialog(final Collection<String> someData, final CountDownLatch latch) {
String[] items = someData.toArray(new String[someData.size()]);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select some data");
builder.setItems(items, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
someEventAnswer = which;
latch.countDown();
}
});
Dialog dialog = builder.create();
dialog.setOwnerActivity(this);
dialog.show();
}
someone 08.07.2012 18:57 # +2
rat4 08.07.2012 20:23 # 0
AlertDialog не могёт в возврат значения.
Пришлось переизобретать ListActivity.
bormand 08.07.2012 19:35 # +3
http://www.youtube.com/watch?v=AyggY_R3jU8
interested 08.07.2012 20:30 # +2