私は故郷のための基本的なツーリストアプリを作ろうとしています。私はlistViewにonItemClickListenerを設定しています。私の目標は、リストアイテムをクリックすると、選択したアイテム(住所、電話番号、GPSの場所など)に関する詳細情報をユーザーに表示するための新しいアクティビティを開くことです。私は意図を送信する前にフラグメント内のすべてのテキストビューを設定します.ContentViewを設定すると、すべての正確な情報が既に入力された状態で表示されます。フラグメントから新しいアクティビティを開始するとブランクアクティビティが開始されます
リストビューをクリックすると、アクティビティが空白アクティビティを開始するという問題があります。エラーメッセージはなく、logCatはテキストビューが正しく更新されたものの、レイアウトで正しく表示されていないことを示しています。
私は数日間この作業に取り組んでおり、誰もが助けることができる助けに感謝します。前もって感謝します。コードは以下のとおりです。
**これは、表示される情報でarrayListを保持するフラグメントです。
public class FoodFragment extends Fragment {
public FoodFragment() {
// Required empty public constructor
}
public TourSite currentSite;
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.sites_listview, container, false);
// Create an ArrayList of TourSite objects for main tab lists
final ArrayList<TourSite> tourSites = new ArrayList<TourSite>();
tourSites.add(new TourSite(R.string.ginasAddress, R.string.ginasNumber, R.string.ginasGPS,
R.string.ginasWeblink, R.drawable.pizza_100, R.string.ginasName));
tourSites.add(new TourSite(R.string.ninosAddress, R.string.ninosnumber, R.string.ninosGPS,
R.string.ninosWeblink, R.drawable.pizza_100, R.string.ninosName));
tourSites.add(new TourSite(R.string.topsAddress, R.string.topsDinerNumber,
R.string.topsDinerGPS, R.string.topsWeblink, R.drawable.restaurant_100,
R.string.topsName));
tourSites.add(new TourSite(R.string.goldenEagleAddress, R.string.goldenEagleNumber,
R.string.goldenEagleGPS, R.drawable.noodles_100, R.string.goldenEagleName));
//Creates adapter that displays tourSites on tabs
TourSiteListAdapter adapter = new TourSiteListAdapter(getActivity(), tourSites);
//finds the listview that were using to display the images and names
ListView listview = (ListView) rootView.findViewById(R.id.siteList);
listview.setAdapter(adapter);
//attaches Listener to listView in order to open new activity with further
// information about the toursite
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//finds the selected list item
currentSite = tourSites.get(position);
//inflates the layout we want to display using the intent below
LayoutInflater inflater1 = (LayoutInflater) getContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View root = inflater1.inflate(R.layout.list_item_info, null, true);
//finds the textViews in the layout that we want to update before
// displaying in activity
TextView addressView = (TextView) root.findViewById(R.id.addressView);
TextView numberView = (TextView) root.findViewById((R.id.numberView));
TextView gpsView = (TextView) root.findViewById(R.id.gpsView);
TextView weblinkView = (TextView) root.findViewById(R.id.weblinkView);
//some toursites dont have phone numbers or websites. This handles that
// while also updateding the content to be displayed
if (currentSite.hasAddress()) {
addressView.setText(currentSite.getmAddress());
addressView.setVisibility(View.VISIBLE);
} else {
addressView.setVisibility(View.GONE);
}
if (currentSite.hasPhone()) {
numberView.setText(currentSite.getmPhone());
numberView.setVisibility(View.VISIBLE);
} else {
numberView.setVisibility(View.GONE);
}
gpsView.setText(currentSite.getmGPSlink());
gpsView.setMovementMethod(LinkMovementMethod.getInstance());
if (currentSite.hasWeblink()) {
weblinkView.setText(currentSite.getmWeblink());
weblinkView.setVisibility(View.VISIBLE);
weblinkView.setMovementMethod(LinkMovementMethod.getInstance());
} else {
weblinkView.setVisibility(View.GONE);
}
//used these logs to make sure the textviews were being updated correctly
Log.d("addressView = ", addressView.getText().toString());
Log.d("numberView = ", numberView.getText().toString());
Log.d("gpsView = ", "" + gpsView.getText().toString());
Log.d("weblinkView = ", weblinkView.getText().toString());
//starts new activity that displays tourSite info
Intent showInfo = new Intent(getContext(), TourSiteInfo.class);
startActivity(showInfo);
}
});
return rootView;
}
}
**このレイアウトを表示するようになっている活動であるが、
public class TourSiteInfo extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_item_info);
}
}
空白である**これは
を表示するようになっているXMLレイアウトであります<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="24dp"
android:id="@+id/infoLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="123 Main Ave, Newark, New Jersey"
android:id="@+id/addressView"
android:padding="16dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="123 Main Ave, Newark, New Jersey"
android:id="@+id/numberView"
android:padding="16dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="123 Main Ave, Newark, New Jersey"
android:id="@+id/gpsView"
android:padding="16dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="123 Main Ave, Newark, New Jersey"
android:id="@+id/weblinkView"
android:padding="16dp"/>
</LinearLayout>
***これは、viewPagerとtabLayoutを含むmainActivity Javaです
0私は日のためにさまざまなソリューションを研究し、しようとしてきたpublic class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager viewpager = (ViewPager) findViewById(R.id.viewpager);
CategoryAdapter adapter = new CategoryAdapter(this, getSupportFragmentManager());
viewpager.setAdapter(adapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewpager);
}
}
** mainAcivityのXML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/mainLayout">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
*** LogCatアプリが起動し、リスト項目が
01/25 14:37:31: Launching app
D/ViewRootImpl: ViewPostImeInputStage processPointer 0
D/ViewRootImpl: ViewPostImeInputStage processPointer 1
D/addressView =: 503 Frank E Rodgers Blvd N, Harrison, NJ 07029
D/numberView =: (973) 482-4883
D/gpsView =: (correct google link displays but stack overflow won't allow it)
D/weblinkView =: ginaspizzanj.com
I/Timeline: Timeline:Activity_launch_requestid
:com.example.android.tourguide
time:222869939
D/SecWifiDisplayUtil: Metadata value : none
D/ViewRootImpl: #1 mView =
com.android.internal.policy.
PhoneWindow$DecorView{d9020d4 I.E...... R.....ID 0,0-0,0}
D/ViewRootImpl: MSG_RESIZED_REPORT:
ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1
W/DisplayListCanvas: DisplayListCanvas is started on unbinded
RenderNode (without mOwningView)
I/Timeline: Timeline: Activity_idle id:
[email protected] time:22287
V/ActivityThread: updateVisibility : ActivityRecord{5e11572
[email protected]
{com.example.android.tourguide/com.example.android.tourguide.MainActivity}} show : true
をクリックされたが、まだ何も働いていない。
アクティビティを起動するたびに、新しい画面のようになります。このビューには、起動する前に何かを設定することはできません。インテントバンドルを追加して観光のパラメータを渡すことはできますが、アクティビティのレイアウトにこれらの値を設定することもできます。 –
ありがとうございますAnurag !!あなたとクリスチャンの両方が私の問題を解決するのを助けました! – joelc1225