有人能告诉我将图像转换为字节数组并将该字节数组转换为base64字符串的代码.我写下面的代码没有得到正确的结果.
String filepath = "/sdcard/Image/ic_launcher.jpg";
File imagefile = new File(filepath);
FileInputStream fis = null;
try {
fis = new FileInputStream(imagefile);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap bm = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100 , baos);
byte[] b = baos.toByteArray();
String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
Run Code Online (Sandbox Code Playgroud)
我得到的结果是
[-1, -40, -1, -32, 0, 16, 74, 70, 73, 70, 0, 1, 1, 1, 0, 72, 0, 72, 0, 0, -1, -20, 4, -7, 68, …
Run Code Online (Sandbox Code Playgroud) 我想将JSON文本{}发送到Web服务并阅读响应.我怎么能从android做到这一点?有哪些步骤,例如创建请求对象,设置内容标题等.
我的代码在这里
public void postData(String result,JSONObject obj) {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpParams myParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(myParams, 10000);
HttpConnectionParams.setSoTimeout(myParams, 10000);
String json=obj.toString();
try {
HttpPost httppost = new HttpPost(result.toString());
StringEntity se = new StringEntity(obj.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
httppost.setEntity(se);
HttpResponse response = httpclient.execute(httppost);
String temp = EntityUtils.toString(response.getEntity());
Log.i("tag", temp);
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
}
Run Code Online (Sandbox Code Playgroud)
我做了什么错误plz纠正我,因为它显示我一个错误的请求错误,但当我在海报发布时,它显示我的状态为Successfull 200 ok
我有列表项目EditText
,我不知道会有多少项目.我有一个问题,当我在输入一些文字EditText
,然后向下滚动ListView
,之后我已经向上滚动再次出现在我的第一个没有文字EditText
,或有其他一些文本EditText
的ListView
.
我已经尝试过TextWatcher
,并将数据保存到数组中,但问题是返回的视图位置ListView
并不总是正确的,所以我从数组中丢失了一些数据.
请帮忙.
这是我的代码:
public class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public String[] Current;
ArrayList<String> MeterName, PreviousReading, Current_Reading;
JSONArray getArray_Meter_Reading;
public EfficientAdapter(Context context, JSONArray getArray_Meter_Reading) {
mInflater = LayoutInflater.from(context);
this.getArray_Meter_Reading = getArray_Meter_Reading;
MeterName = new ArrayList<String>();
PreviousReading = new ArrayList<String>();
for (int i = 0; i < getArray_Meter_Reading.length(); i++) {
try {
String Meter_Name = getArray_Meter_Reading.getJSONObject(i)
.getString("MeterName").toString();
String previous_Meter_Reading = getArray_Meter_Reading
.getJSONObject(i).getString("PrevMeterReading") …
Run Code Online (Sandbox Code Playgroud) 我为一个活动指定了两个单独的布局xml文件,一个用于res/layout文件夹中的Portrait,另一个用于res/layout-land文件夹中的Landscape.我的实际问题是,当我以纵向模式启动应用程序时,它需要ui从布局和即时我旋转我的手机它不需要从布局 - 土地文件夹中的xml它需要从布局文件夹ui,如果我在横向模式下启动我的应用程序它从layout-land文件夹中获取xml并立即将我旋转到肖像模式它从布局中获取xml-land ui不会更改为纵向ui.
可以任何伙伴告诉我什么是问题是有什么需要的PLZ帮助我解决这个问题.
提前致谢 .
this is my landscape ui xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget57"
android:layout_width="400dp"
android:layout_height="400dp"
android:layout_gravity="center|center_vertical"
android:layout_marginTop="30dp"
android:orientation="vertical" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp" >
<TextView
android:id="@+id/txtName"
android:layout_width="90dp"
android:text="@string/UserName" />
<EditText
android:id="@+id/edName"
android:imeOptions="actionNext|actionDone"
android:paddingRight="10dp"
android:singleLine="true"
android:width="240dp" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/txtPass"
android:layout_width="90dp"
android:text="@string/PassWord" />
<EditText
android:id="@+id/edPass"
android:imeOptions="actionGo"
android:paddingRight="10dp"
android:password="true"
android:singleLine="true"
android:width="240dp" />
</TableRow>
<LinearLayout
android:id="@+id/widget57"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical" >
<Button
android:id="@+id/btnLogin"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="@string/btn_GO"
android:textSize="19sp" >
</Button> …
Run Code Online (Sandbox Code Playgroud) 我在linelayout里面有tablelayout但是它向我显示了这个警告消息
这个TableLayout布局或者它的LinearLayout父级是没用的如何克服这个警告可以帮助我.提前致谢
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableLayout>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" >
<TextView
android:id="@+id/txtPass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:text="Password"
android:textSize="18sp"
android:width="100dp" />
<EditText
android:id="@+id/edPass"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:password="true" >
<requestFocus />
</EditText>
</TableRow>
</TableLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我有一个listview
内部scrollview
,但问题scrollview
是滚动但listview
不滚动.我认为这是由于这个原因scrollView
.
有工作解决方案的人可以在这里作为参考发布吗?