gpt4 book ai didi

java - 显示 fragment 时 EditText 未显示在 ListFragment 上方?

转载 作者:行者123 更新时间:2023-12-01 12:13:41 25 4
gpt4 key购买 nike

我正在构建一个使用 Fragments 来显示 UI 的主/详细信息应用程序。我有一个显示 ListListFragment,我希望在其上方有一个 EditText 以输入将从 Web API 提取的数据关键字。我的问题是 EditText 没有显示在我的 ListFragment 中的 List 上方。这是我的一些代码:

Display_Fragment.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="fill_parent"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="@+id/myEditText"
android:inputType="text"
android:hint="@string/hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:id="@+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginTop="20dp"/>
</LinearLayout>
</LinearLayout>

MyListFragment.java

package com.brianstacks.fragmentandfilefundamentals.fragments;

import android.app.AlertDialog;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.brianstacks.fragmentandfilefundamentals.R;

/**
* Created by Brian Stacks
* on 11/24/14
* for FullSail.edu.
*/
public class MyListFragment extends ListFragment {

public static final String TAG = "MyListFragment.TAG";

public static MyListFragment newInstance() {
MyListFragment frag = new MyListFragment();
return frag;
}

@Override
public void onActivityCreated(Bundle _savedInstanceState) {
super.onActivityCreated(_savedInstanceState);
String[] teams = getResources().getStringArray(R.array.teamList);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, teams);
setListAdapter(adapter);
}
public void onListItemClick(ListView _l, View _v, int _position, long _id) {
String team = (String)_l.getItemAtPosition(_position);
new AlertDialog.Builder(getActivity())
.setTitle(R.string.team)
.setMessage(getString(R.string.selected, team))
.setPositiveButton(R.string.ok, null)
.show();
}
}

MainActivity.java

/*
* Brian Stacks
* Java 2
* 11-24-2014
* */
package com.brianstacks.fragmentandfilefundamentals;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


import com.brianstacks.fragmentandfilefundamentals.fragments.DetailFragment;
import com.brianstacks.fragmentandfilefundamentals.fragments.MyListFragment;


public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager mgr = getFragmentManager();
FragmentTransaction trans = mgr.beginTransaction();

MyListFragment frag = MyListFragment.newInstance();
trans.replace(R.id.fragment_container, frag, MyListFragment.TAG);
DetailFragment dFrag = DetailFragment.newInstance();
trans.replace(R.id.fragment_container2,dFrag,DetailFragment.TAG);
trans.commit();


}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

// Async task method to do network action in
private class MyTask extends AsyncTask<String ,String ,String> {

@Override
protected void onPreExecute() {

}

@Override
protected String doInBackground(String... params) {
return "";
}

@Override
protected void onPostExecute(String result) {


}

@Override
protected void onProgressUpdate(String... values) {

}
}

// method to get the data from ASYNC task
private void requestData(String uri) {
MyTask task = new MyTask();
task.execute(uri);
}

// method to check internet connectivity
protected boolean isOnline(){
ConnectivityManager cm =(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
return netInfo != null && netInfo.isConnectedOrConnecting();

}

}

它显示了我的List,但没有显示我的EditText

最佳答案

你在哪里调用了 Displayfragment.xml???

关于java - 显示 fragment 时 EditText 未显示在 ListFragment 上方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27129060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com