package blog.naver.com.seongjun0926.pos;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.text.Editable;
import android.text.InputType;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import java.io.ObjectStreamException;
import java.util.ArrayList;
import java.util.Objects;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class Table_Select_Activity extends ActionBarActivity implements AdapterView.OnItemLongClickListener {
boolean databaseCreated = false;
boolean tableCreated = false;
private SQLiteDatabase db;
private static final String TAG = "MENU_DATABASE";
private static String DATABASE_NAME = "MENU_DATABASE";
private static String TABLE_NAME = "MENU_PRICE";
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_table_select);
Log.i("tag","onCreate");
db = openOrCreateDatabase(DATABASE_NAME, MODE_WORLD_WRITEABLE, null);
showDatabase();
list.setOnItemLongClickListener(this);
}
private boolean openDatabase() {
Log.i("tag", "openDatabase");
println("opening database [" + DATABASE_NAME + "].");
return true;
}
private void println(String msg) {
Log.d(TAG, msg);
}
private void showDatabase(){
Log.i("tag", "showDatabase");
list = (ListView) findViewById(R.id.listView2);
boolean isOpen = openDatabase();
if (isOpen) {
Cursor cursor = executeRawQueryParam();
startManagingCursor(cursor);
String[] columns = new String[]{"name", "price"};
int[] to = new int[]{R.id.name_entry, R.id.price_entry};
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.listitem, cursor, columns, to);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,columns);
list.setAdapter(mAdapter);
}
}
private Cursor executeRawQueryParam() {
Log.i("tag", "executeRawQueryParam");
println("\nexecuteRawQueryParam called. \n");
String SQL = "select * from " + TABLE_NAME;
Log.i("tag", "SQL=" + SQL);
Cursor c1 = db.rawQuery(SQL, null);
Log.i("tag", "c1=" + c1);
return c1;
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
이부분에서 여러 방법을 해봤지만 ㅠㅠ 도저히 되질않습니다 좀 도와주세요 고수님
오래 클릭된 곳의 이름을 가져오고 싶은데 ... 도저히 되질 않습니다 ㅠㅠ
도와주세요 ㅎ허허ㅓ ㅠㅠㅠ
adapterView.getTextAlignment();
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("수량");
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_NUMBER);
alert.setView(input);
alert.setPositiveButton("취소", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.setNegativeButton("확인",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Editable value = input.getText();
Log.i("tag","value="+value);
}
});
alert.show();
return true;
}
}