我正在将一个旧程序转移到一个选项卡和片段实现。用户输入一个 Id 进行搜索,然后点击提交。但是我的“提交按钮”什么也没做。
我尝试了几种替代编码变体,但得到了相同的结果 - 死气沉沉!
这是 XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/setUpAthletesTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#CCFFFF" >
<TextView
android:id="@+id/instructionText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/instructionText"
android:textColor="#FF0000"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:stretchColumns="*" >
<EditText
android:id="@+id/editTextAthlete0"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:hint="@string/hintText"
android:inputType="number" />
<TextView
android:id="@+id/textAthleteName0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:hint="@string/athleteHintName0"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
这是我的标签/片段
public class Tab3Fragment extends Fragment {
/* (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
/* Begin Insertion */
LayoutInflater myInflater = inflater;
ViewGroup myContainer = container;
if(inflater == null) myInflater = inflater;
if(container == null) myContainer = container;
Log.d(APP_TAG,"At line 50 of Tab3Fragment myInflater = " + myInflater + " and myContainer = " + myContainer);
getAthleteInfoFromExistingDatabase(myInflater,myContainer);
LinearLayout tab3LinearLayout = (LinearLayout) inflater.inflate(R.layout.tab_frag3_layout, container, false);
View mySubmitButton = tab3LinearLayout.findViewById(R.id.submitButton);
((Button) mySubmitButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(Tab3Fragment.this.getActivity().getBaseContext(),
"clicked on Submit Button", Toast.LENGTH_LONG).show();
Intent intent = new Intent();
intent.setClass(getActivity(), RetrieveAthleteData.class);
startActivity(intent);
}
});
return (LinearLayout)inflater.inflate(R.layout.tab_frag3_layout, container, false);
}
当我点击提交时,Toast 框和 Intent 都不会关闭。
谢谢你看我的问题。
问题解决了!感谢 Dirk 建议将名称更改为全部小写。