我正在为朋友乐队制作一款应用,并且正在使用名为parse的云存储API。我正在尝试从云中获取一个字符串,然后在我的编辑文本中显示它,并且想法是使文本成为您想要的,然后将其上载到数据库。我可以这样做,但每当我更改文本然后将手机水平翻转然后再垂直移动它会删除我的编辑。此外,看起来触摸已停止为该特定布局工作。我有一个TabHost并且切换标签工作正常,但每当我尝试单击按钮时我什么也得不到,我也无法在EditText中移动光标。我在我的onClick方法中为我的按钮放置了断点和祝酒,没有任何东西被解雇。我不知道发生了什么。请帮忙!
爪哇
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的云存储库。我不知道是否有人在这里熟悉它或者它是否会干扰,但我真的很感激一些帮助。谢谢!
答案 0 :(得分:0)
删除initialize()
中的内容,并将代码直接放在onCreate()
方法中..我不知道为什么会发生这种情况但是我遇到了这个确切的问题而这样做对我有帮助
答案 1 :(得分:0)
我修好了!我的TabHost没有使用RelativeLayout,因此打破了我的观点。我将布局添加到我的TabHost中,现在一切正常!