Last active
August 29, 2015 14:05
-
-
Save ktaka/51185fe5a47256681ada to your computer and use it in GitHub Desktop.
Practice in Utility (1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RelativeLayout 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" | |
tools:context="jp.techinstitute.syllabus.CourseDetail" > | |
<TextView | |
android:id="@+id/dateText" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:textAppearance="?android:attr/textAppearanceLarge" | |
android:text="@string/hello_world" /> | |
<TextView | |
android:id="@+id/titleText" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignLeft="@id/dateText" | |
android:layout_below="@id/dateText" | |
android:textAppearance="?android:attr/textAppearanceLarge" | |
android:text="@string/hello_world" /> | |
<TextView | |
android:id="@+id/teacherItemName" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignLeft="@id/titleText" | |
android:layout_below="@id/titleText" | |
android:layout_marginTop="11dp" | |
android:textAppearance="?android:attr/textAppearanceMedium" | |
android:text="講師:" /> | |
<TextView | |
android:id="@+id/teacherText" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_toRightOf="@id/teacherItemName" | |
android:layout_below="@id/titleText" | |
android:layout_alignBaseline="@id/teacherItemName" | |
android:textAppearance="?android:attr/textAppearanceMedium" | |
android:text="@string/hello_world" /> | |
<TextView | |
android:id="@+id/detailText" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignLeft="@id/titleText" | |
android:layout_below="@id/teacherItemName" | |
android:layout_marginTop="11dp" | |
android:textAppearance="?android:attr/textAppearanceMedium" | |
android:text="@string/hello_world" /> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RelativeLayout 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" | |
tools:context="jp.techinstitute.syllabus.MainActivity" > | |
<ListView | |
android:id="@+id/listview" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
/> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.techinstitute.syllabus; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.widget.TextView; | |
public class CourseDetail extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_course_detail); | |
Intent intent = getIntent(); | |
String dateStr = intent.getStringExtra("date"); | |
String titleStr = intent.getStringExtra("title"); | |
String teacherStr = intent.getStringExtra("teacher"); | |
String detailStr = intent.getStringExtra("detail"); | |
TextView dateText = (TextView)findViewById(R.id.dateText); | |
dateText.setText(dateStr); | |
TextView titleText = (TextView)findViewById(R.id.titleText); | |
titleText.setText(titleStr); | |
TextView teacherText = (TextView)findViewById(R.id.teacherText); | |
teacherText.setText(teacherStr); | |
TextView detailText = (TextView)findViewById(R.id.detailText); | |
detailText.setText(detailStr); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.course_detail, 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(); | |
if (id == R.id.action_settings) { | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" > | |
<TextView | |
android:id="@+id/date" | |
android:layout_width="56dp" | |
android:layout_height="match_parent" | |
android:layout_alignParentLeft="true" | |
android:text="8/28" | |
android:textColor="@android:color/black" /> | |
<TextView | |
android:id="@+id/title" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:textColor="@android:color/black" | |
android:text="ユーティリティによる実践(1)" | |
android:layout_toRightOf="@id/date" /> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.techinstitute.syllabus; | |
import java.util.ArrayList; | |
import java.util.List; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.LayoutInflater; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.AdapterView; | |
import android.widget.AdapterView.OnItemClickListener; | |
import android.widget.ArrayAdapter; | |
import android.widget.ListView; | |
import android.widget.TextView; | |
public class MainActivity extends Activity implements OnItemClickListener { | |
private class CourseItem { | |
String date; | |
String title; | |
String teacher; | |
String detail; | |
} | |
private List<CourseItem> itemList; | |
private ItemAdapter adapter; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
itemList = new ArrayList<CourseItem>(); | |
adapter = new ItemAdapter(getApplicationContext(), 0, itemList); | |
ListView listView = (ListView)findViewById(R.id.listview); | |
listView.setAdapter(adapter); | |
setCourseData(); | |
listView.setOnItemClickListener(this); | |
} | |
private void setCourseData() { | |
CourseItem item = new CourseItem(); | |
item.date = "8/28"; | |
item.title = "ユーティリティによる実践(1)"; | |
item.teacher = "高橋憲一"; | |
item.detail = "この講義では一つのアプリとして仕上げることを目指します。"; | |
itemList.add(item); | |
item = new CourseItem(); | |
item.date = "9/2"; | |
item.title = "ユーティリティによる実践(2)"; | |
item.teacher = "高橋憲一"; | |
item.detail = "一つのアプリを仕上げることを目指す2回目。"; | |
itemList.add(item); | |
} | |
private class ItemAdapter extends ArrayAdapter<CourseItem> { | |
private LayoutInflater inflater; | |
public ItemAdapter(Context context, int resource, | |
List<CourseItem> objects) { | |
super(context, resource, objects); | |
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
View view = inflater.inflate(R.layout.lecture_row, null, false); | |
TextView dateView = (TextView) view.findViewById(R.id.date); | |
TextView titleView = (TextView) view.findViewById(R.id.title); | |
CourseItem item = getItem(position); | |
dateView.setText(item.date); | |
titleView.setText(item.title); | |
return view; | |
} | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.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(); | |
if (id == R.id.action_settings) { | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
@Override | |
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { | |
CourseItem item = (CourseItem)arg0.getItemAtPosition(arg2); | |
Intent intent = new Intent(this, CourseDetail.class); | |
intent.putExtra("date", item.date); | |
intent.putExtra("title", item.title); | |
intent.putExtra("teacher", item.teacher); | |
intent.putExtra("detail", item.detail); | |
startActivity(intent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment