Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Android Programming List App using fragments Homework 3 Minimum SDK must be API

ID: 3605296 • Letter: A

Question

Android Programming List App using fragments

Homework 3

Minimum SDK must be API 25

Android Emulator must be Nexus 6

Warrior Roster http://www.nba.com/warriors/roster/

In this App, you are going to write an app to present Warriors’ roster.

1. You are required to use Fragments

2. Once the app is open, it should present a list of Warrior rosters with PNames and Numbers. You don’t need to include everyone on the official roster. It is good if you have five to seven players in your app’s list.

3. Once an item in the list is tapped, the view should be switched to details of the player.

4. The detail view of one player should present a. The player’s photo which can be downloaded from the link above. b. Player’s number c. Player’s name d. Player’s position

5. The first item of the list view should be your name. Once it is tapped, the detail view should show your name and email address. Pictures are not needed for this view.

[*] If your program cannot start, that’s a zero.

[5%] item in list view and Detail view of your name and email address.

[30%] for correct User Interface Appearance. Once it starts, it should show the list view. Must use fragment to do the homework

[35%] for correct listeners that can open detail view

[30%] for Correctly detail information of all players (five to seven players)

Explanation / Answer

package com.listapp;

import android.app.ListFragment;
import android.content.Context;
import android.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends FragmentActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Fragment fragment =new MyListFragment();
getFragmentManager().beginTransaction().replace(R.id.container, fragment).addToBackStack(null).commit();


}

public static class MyListFragment extends ListFragment implements AdapterView.OnItemClickListener {
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.litview, container, false);
return view;
}

List<Roster> rosterList=new ArrayList<>();
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);


rosterList.add(new Roster("Praveen","1","",""));
rosterList.add(new Roster("Jordan Bell","2","Forward","http://ak-static.cms.nba.com/wp-content/uploads/headshots/nba/latest/260x190/1628395.png"));
rosterList.add(new Roster("Chris Boucher","3","Forward","http://ak-static.cms.nba.com/wp-content/uploads/headshots/nba/latest/260x190/1628449.png"));
rosterList.add(new Roster("Omri Casspi","4","Forward","http://ak-static.cms.nba.com/wp-content/uploads/headshots/nba/latest/260x190/201956.png"));
rosterList.add(new Roster("Quinn Cook","5","Guard","http://ak-static.cms.nba.com/wp-content/uploads/headshots/nba/latest/260x190/1626188.png"));
rosterList.add(new Roster("Stephen Curry","6","Guard","http://ak-static.cms.nba.com/wp-content/uploads/headshots/nba/latest/260x190/201939.png"));
rosterList.add(new Roster("Kevin","7","Forward","http://ak-static.cms.nba.com/wp-content/uploads/headshots/nba/latest/260x190/201142.png"));

RosterAdapter<Roster> adapter = new RosterAdapter<Roster>(getContext(), rosterList);
setListAdapter(adapter);

setListAdapter(adapter);
getListView().setOnItemClickListener(this);
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Fragment fragment = DisplayFragment.newInstance(rosterList.get(position));
getActivity().getFragmentManager().beginTransaction().replace(R.id.container, fragment).addToBackStack(null).commit();

}
}


private static class RosterAdapter<Roster> extends ArrayAdapter<Roster> {
private final Context context;
private List<com.listapp.Roster> rosterList;

public RosterAdapter(Context context,List<com.listapp.Roster> rosterList) {
super(context, R.layout.activity_main, (List<Roster>) rosterList);
this.context = context;
this.rosterList = rosterList;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.activity_main, parent, false);
((TextView) rowView.findViewById(R.id.playerNumber)).setText(rosterList.get(position).getPlayerNumber());
((TextView) rowView.findViewById(R.id.playerName)).setText(rosterList.get(position).getPlayerName());


return rowView;
}
}
}

////

package com.listapp;

import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

public class DisplayFragment extends Fragment {

Roster roster;
public static DisplayFragment newInstance(Roster roster) {

Bundle args = new Bundle();

DisplayFragment fragment = new DisplayFragment();
fragment.setArguments(args);
fragment.roster=roster;
return fragment;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rowView = inflater.inflate(R.layout.detailview, container,
false);
((TextView) rowView.findViewById(R.id.playerName)).setText(roster.getPlayerNumber());
((TextView) rowView.findViewById(R.id.playerNumber)).setText(roster.getPlayerNumber());
((TextView) rowView.findViewById(R.id.playerposition)).setText(roster.getPlayerPosition());

Picasso.with(getActivity()).load(roster.getPlayerImage()).into(((ImageView)rowView.findViewById(R.id.image)));
return rowView;
}


}

//////

package com.listapp;

public class Roster {

String playerName,
playerNumber,playerPosition,playerImage;


public Roster(String playerName, String playerNumber, String playerPosition, String playerImage) {
this.playerName = playerName;
this.playerNumber = playerNumber;
this.playerPosition = playerPosition;
this.playerImage = playerImage;
}

public String getPlayerName() {
return playerName;
}

public String getPlayerNumber() {
return playerNumber;
}

public String getPlayerPosition() {
return playerPosition;
}

public String getPlayerImage() {
return playerImage;
}
}