ユーザーに価格を入力させようとしていますEditText
...つまり"20.00"
、その編集テキストから値を文字列として取得します。次に、その文字列をデータとして使用して、キーの下の「my server」別名 parse.com に値としてアップロードし"Price"
ます。エミュレーターを実行するたびに"20.00"
、編集テキストに入力し、サーバーをチェックすると、新しいエントリがポップアップしません。私のlogcatは次を返します:
03-23 21:14:20.607: V/EditText(1697): 20.00
上記で別の文字列を作成し、単純に値を指定するとします。"Price"
次に、代わりにキーの下に置きmyString
、エミュレーターを実行します。サーバーはこれを受け取り、すべてがうまくいきます。
キーの下に設定された値"Price"
は文字列であり、logcat はEditText
を使用するたびに を返すため、複数のチュートリアル/回答を調べたにもかかわらず、 の代わりにmyString
を使用していると信じるようになりました。使用する必要がある編集テキストから文字列を取得します。EditText
String
price = (EditText) findViewById(R.id.editText1);
String newString = price.getText().toString();
私は自分のコードに持っています。
また、検索機能を持つ 2 つSearchView
の とListView
上記の 2 つの があるため、コードが少し長くなります。私のコードはまったくエラーにならず、この小さな問題以外は問題なく動作します。
TapDeal.java
- 問題クラス:
package com.alpha.dealtap;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import com.parse.Parse;
import com.parse.ParseObject;
public class TapDeal extends Activity {
Button b1;
String newString;
// List view
private ListView lv;
private ListView lv2;
// Listview Adapter
ArrayAdapter<String> adapter;
ArrayAdapter<String> adapter2;
// Search EditText
EditText inputSearch;
EditText inputSearch2;
EditText price;
// ArrayList for Listview
ArrayList<HashMap<String, String>> productList;
ArrayList<HashMap<String, String>> productList2;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tapdeal);
// Listview Data
String products[] = { "Dubra", "Keystone Light", "Keystone",
"Smirnoff", "Jack Daniels", "Captain Morgan", "Grey Goose",
"Burnetts", "Kettle One", "Corona", "Franzia", "Budweiser" };
String size[] = { "6 Pack", "12 Pack", "30 Pack", "750ml", "Handle",
"1 liter", "3 Liter Box", "Half Pint", "1 Pint" };
lv = (ListView) findViewById(R.id.list_view);
lv2 = (ListView) findViewById(R.id.list_view2);
inputSearch = (EditText) findViewById(R.id.inputSearch);
inputSearch2 = (EditText) findViewById(R.id.inputSearch2);
// Adding items to listview
adapter = new ArrayAdapter<String>(this, R.layout.listitem,
R.id.product_name, products);
adapter2 = new ArrayAdapter<String>(this, R.layout.size, R.id.size,
size);
lv.setAdapter(adapter);
lv2.setAdapter(adapter2);
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2,
int arg3) {
// When user changed the Text
TapDeal.this.adapter.getFilter().filter(cs);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
inputSearch2.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
TapDeal.this.adapter2.getFilter().filter(s);
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
b1 = (Button) findViewById(R.id.button1);
price = (EditText) findViewById(R.id.editText1);
String newString = price.getText().toString();
Parse.initialize(this, "xxxx", "yyyy");
ParseObject dealinfo = new ParseObject("Deals");
dealinfo.put("Brand", "Budweiser");
dealinfo.put("Size", "6");
dealinfo.put("Price", newString);
dealinfo.saveInBackground();
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.v("EditText", price.getText().toString());
}
});
}
}
("xxxx"
と"yyyy"
は私の秘密鍵です)。
tapdeal.xml
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- Editext for Search -->
<EditText
android:id="@+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Brand of Alcohol"
android:inputType="textVisiblePassword" />
<!-- List View -->
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="52dp" />
<EditText
android:id="@+id/inputSearch2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="Enter the Size"
android:inputType="textVisiblePassword" />
<ListView
android:id="@+id/list_view2"
android:layout_width="fill_parent"
android:layout_height="54dp"
android:layout_weight="0.16" />
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:ems="10"
android:hint="Enter the Price"
android:inputType="numberDecimal" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:text="Tap it"
android:textSize="23dp" />
</LinearLayout>
マニフェスト:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alpha.dealtap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Main"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Search_Page"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.SEARCH_PAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".DealPage"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.DEALPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".StorePage"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.STOREPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Map"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.alpha.dealtap.MAP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TapDeal"
android:label="TapDeal"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="com.alpha.dealtap.TAPDEAL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
ご協力ありがとうございました!