我正在为朋友乐队制作一个应用程序,并且正在使用一个名为 parse 的云存储 API。我正在尝试从云中获取一个字符串,然后将其显示在我的编辑文本中,其想法是使文本成为您想要的,然后将其上传到数据库。我可以这样做,但是每当我更改文本然后将手机水平翻转然后再次垂直时,它都会删除我的编辑。此外,触摸似乎已停止对该特定布局起作用。我有一个 TabHost 并且切换选项卡工作正常,但是每当我尝试单击该按钮时,我什么也得不到,也无法在 EditText 中移动光标。我在我的按钮的 onClick 方法中放置了断点和 toast,没有任何东西被触发。我不知道发生了什么。请帮忙!
爪哇
package com.example.undaunted.admin;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.Toast;
import com.parse.GetCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.SaveCallback;
public class UndauntedAdminMain extends Activity {
TabHost tabHost;
Button saveWelcomeText;
EditText welcomeText;
ParseFile file;
ParseObject welcomeTextObject;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.undaunted_main);
welcomeText = (EditText) findViewById(R.id.editText1);
Parse.initialize(this, "REMOVED",
"REMOVED");
initialize();
}
public void initialize() {
tabHost = (TabHost) findViewById(R.id.tabHost);
tabHost.setup();
TabSpec spec = tabHost.newTabSpec("Welcome");
spec.setContent(R.id.welcomeTab);
spec.setIndicator("Welcome");
tabHost.addTab(spec);
TabSpec spec3 = tabHost.newTabSpec("Biographies")
.setContent(R.id.biographyTab).setIndicator("Biographies");
tabHost.addTab(spec3);
// tabHost.newTabSpec("Biographies").setIndicator("Biographies").setContent();
TabSpec spec2 = tabHost.newTabSpec("Gallery");
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.galleryTab);
relativeLayout.setBackgroundColor(Color.BLACK);
spec2.setContent(R.id.galleryTab);
spec2.setIndicator("Gallery");
tabHost.addTab(spec2);
ParseQuery query2;
query2 = new ParseQuery("Welcome");
query2.getInBackground("fdZL8G4PIk", new GetCallback() {
@Override
public void done(ParseObject arg0, ParseException arg1) {
// TODO Auto-generated method stub
if (arg1 == null) {
// welcomeTextObject = arg0;
// welcomeText.setText(welcomeTextObject.getString(
// "WelcomeText").toString());
} else {
welcomeText.setText("Failed to load data");
}
}
});
saveWelcomeText = (Button) findViewById(R.id.saveWelcomeText);
saveWelcomeText.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
welcomeTextObject.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException arg0) {
// TODO Auto-generated method stub
welcomeTextObject.put("WelcomeText",
welcomeText.getText());
welcomeTextObject.saveInBackground();
Toast.makeText(getApplicationContext(), "Data sent",
Toast.LENGTH_SHORT).show();
}
});
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_undaunted_admin_main, menu);
return true;
}
}
XML
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tabHost" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="@+android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/welcomeTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:id="@+id/saveWelcomeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Save" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10" >
<requestFocus />
</EditText>
</RelativeLayout>
<RelativeLayout
android:id="@+id/galleryTab"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RelativeLayout>
<RelativeLayout
android:id="@+id/biographyTab"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView
android:id="@+id/memberList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="@+id/biographyTab"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/showDatesTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="@+id/showDateList"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_above="@+id/showDatesTab">
</ListView>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
其他详细信息,我正在使用一个名为 Parse 的云存储库。我不知道这里是否有人熟悉它,或者它是否会造成干扰,但我真的很感激一些帮助。谢谢!