Skip to content

Commit

Permalink
ListView with Image didn't work. Added classes for later.
Browse files Browse the repository at this point in the history
  • Loading branch information
elenimikro committed Oct 27, 2013
1 parent 3456116 commit 9e3af1a
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 28 deletions.
11 changes: 3 additions & 8 deletions HackMetro/res/layout/activity_display_journey.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".DisplayJourneyActivity" >
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<TextView
android:id="@+id/journey_info"
Expand Down
13 changes: 6 additions & 7 deletions HackMetro/res/layout/journey_list_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="horizontal"
tools:context=".DisplayJourneyActivity" >
android:gravity="center_vertical">

<ImageView
android:id="@+id/imageView"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="9dp"
android:layout_alignParentTop="true"/>
android:layout_alignParentTop="true"
android:contentDescription="icon"/>

<TextView
android:layout_alignBottom="@+id/imageView"
android:layout_width="97dp"
Expand All @@ -26,4 +23,6 @@
android:layout_alignParentRight="true"
android:gravity="center_vertical"/>



</RelativeLayout>
1 change: 1 addition & 0 deletions HackMetro/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<string name="stations_search_title">Search station</string>
<string name="select_time">Select Time (Optional)</string>
<string name="journey_details">Enter your journey details</string>
<string name="icon">icon</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ protected void onCreate(Bundle savedInstanceState) {

// Get the right List
ListView hopListView = (ListView) findViewById(R.id.hop_list);
// List<String> hopList = FakeModel.getHopList(journeyInfo);
// Journey journey = FakeModel.getFakeJourney(journeyInfo);
// StationItemAdapter adapter = new StationItemAdapter(this,
// R.layout.journey_list_row, journey);
// hopListView.setAdapter(adapter);

List<String> hopList = FakeModel.getHopList(journeyInfo);
Journey journey = FakeModel.getFakeJourney(journeyInfo);
StationItemAdapter adapter = new StationItemAdapter(this,
R.layout.journey_list_row, journey);
// StationItemAdapter adapter = new StationItemAdapter(this,
// R.layout.journey_list_row, journey);
hopListView.setAdapter(new ArrayAdapter<String>(
DisplayJourneyActivity.this,
android.R.layout.simple_list_item_1, hopList));

}

@Override
Expand Down
15 changes: 11 additions & 4 deletions HackMetro/src/com/github/ignazio1977/hackmetro/FakeModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ public static List<String> getHopList(String journeyInfo) {
}
}

public static final Journey fJourney_1 = new Journey();

public static Journey getFakeJourney(String journeyInfo) {
Hop hop1 = new Hop();
Journey toReturn = new Journey();
List<String> hopList = getHopList(journeyInfo);
for (int i = 0; i < hopList.size(); i++) {
FakeNamedLocation fakeStartLocation = new FakeNamedLocation(
hopList.get(i));
Hop hop = new Hop();
hop.setStart(fakeStartLocation);
toReturn.addHop(hop);
}

return null;
return toReturn;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.github.ignazio1977.hackmetro;

import com.github.ignazio1977.hackmetro.model.NamedLocation;
import com.google.common.base.Optional;

public class FakeNamedLocation implements NamedLocation {
private Optional<String> name = Optional.absent();

public FakeNamedLocation(String name) {
this.name = Optional.of(name);
}

@Override
public Optional<Double> getLongitude() {
// TODO Auto-generated method stub
return null;
}

@Override
public Optional<Double> getLatitude() {
// TODO Auto-generated method stub
return null;
}

@Override
public Optional<String> getName() {
// TODO Auto-generated method stub
return name;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,21 @@ public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) rowView.findViewById(R.id.textView);

Station item = getItem(position);
textView.setText(item.getName().get());
// textView.setText(item.getName().get());
textView.setText("test");
String imageFile = getImageFile(position);

// get input stream
InputStream ims = null;
try {
ims = context.getAssets().open(imageFile);
InputStream ims = context.getAssets().open(imageFile);
// load image as Drawable
Drawable d = Drawable.createFromStream(ims, "src");
// set image to ImageView
imageView.setImageDrawable(d);
} catch (IOException e) {
e.printStackTrace();
}
// load image as Drawable
Drawable d = Drawable.createFromStream(ims, null);
// set image to ImageView
imageView.setImageDrawable(d);

return rowView;
}

Expand Down

0 comments on commit 9e3af1a

Please sign in to comment.