 |
|
ขอสอบถามด้วยครับว่า ถ้าผมต้องการ กดปุ่ม + - เพื่อเพิ่มค่าเข้าไปใน EditText ทำอย่างไร คือ Field นี้เป็นตัวเลข ผมลองทำแล้วแล้วไม่ได้รบกวนด้วยครับ * ผมแนบโค็ดมาด้วยครับ

Code (Android-Java)
package com.app.mobilerest;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class OrderDetail extends Activity {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
&& (keyCode == KeyEvent.KEYCODE_BACK)
&& event.getRepeatCount() == 0) {
onBackPressed();
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onBackPressed() {
Toast.makeText(OrderDetail.this, "Back", Toast.LENGTH_SHORT).show();
Intent newActivity = new Intent(OrderDetail.this, TakeOrder.class);
startActivity(newActivity);
finish();
return;
}
public String rUserID,rProductCode,rProductName,rOrderUnit,rOrderPrice,rOrderQty,rProductUrl,rRemark;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.order_detail);
Intent intent= getIntent();
rUserID = intent.getStringExtra("sUserID");
rProductCode = intent.getStringExtra("sProductCode");
rProductName = intent.getStringExtra("sProductName");
rOrderUnit = intent.getStringExtra("sOrderUnit");
rOrderPrice = intent.getStringExtra("sOrderPrice");
rOrderQty = intent.getStringExtra("sOrderQty");
rProductUrl = intent.getStringExtra("sProductUrl");
rRemark = intent.getStringExtra("sRemark");
// Product Name
TextView txtName = (TextView)findViewById(R.id.textView2);
txtName.setText(rProductName+"("+rOrderUnit+")");
// Product Price
TextView txtPrice = (TextView)findViewById(R.id.textView4);
txtPrice.setText(rOrderPrice);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap((Bitmap)loadBitmap(rProductUrl));
// Product Order Qty
TextView txtOrderQty = (TextView)findViewById(R.id.edtOrderQty);
txtOrderQty.setText(rOrderQty);
// Product Order Qty
TextView txtRemark = (TextView)findViewById(R.id.edtRemark);
txtRemark.setText(rRemark);
// Incress Order Quantity
final Button btnInc = (Button) findViewById(R.id.bntInc);
// Perform action on click
btnInc.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// to do
TextView txtOrderQty = (TextView)findViewById(R.id.edtOrderQty);
txtOrderQty.setText(rOrderQty+1);
}
});
// Decress Order Quantity
final Button btnDec = (Button) findViewById(R.id.bntInc);
// Perform action on click
btnInc.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// to do
TextView txtOrderQty = (TextView)findViewById(R.id.edtOrderQty);
txtOrderQty.setText(rOrderQty+1);
}
});
}
/***** Get Image Resource from URL (Start) *****/
private static final String TAG = "Image";
private static final int IO_BUFFER_SIZE = 4 * 1024;
public static Bitmap loadBitmap(String url) {
Bitmap bitmap = null;
InputStream in = null;
BufferedOutputStream out = null;
try {
in = new BufferedInputStream(new URL(url).openStream(), IO_BUFFER_SIZE);
final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE);
copy(in, out);
out.flush();
final byte[] data = dataStream.toByteArray();
BitmapFactory.Options options = new BitmapFactory.Options();
//options.inSampleSize = 1;
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,options);
} catch (IOException e) {
Log.e(TAG, "Could not load Bitmap from: " + url);
} finally {
closeStream(in);
closeStream(out);
}
return bitmap;
}
private static void closeStream(Closeable stream) {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
android.util.Log.e(TAG, "Could not close stream", e);
}
}
}
private static void copy(InputStream in, OutputStream out) throws IOException {
byte[] b = new byte[IO_BUFFER_SIZE];
int read;
while ((read = in.read(b)) != -1) {
out.write(b, 0, read);
}
}
/***** Get Image Resource from URL (End) *****/
// end main
}
|
 |
 |
 |
 |
Date :
2013-03-26 01:08:19 |
By :
shinaphol |
|
 |
 |
 |
 |
|
|
 |