Skip to content
Open

V0 #1

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added a
Empty file.
8 changes: 8 additions & 0 deletions study/FragmentUI/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
1 change: 1 addition & 0 deletions study/FragmentUI/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions study/FragmentUI/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions study/FragmentUI/.idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions study/FragmentUI/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions study/FragmentUI/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions study/FragmentUI/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions study/FragmentUI/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions study/FragmentUI/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions study/FragmentUI/basicfragment001/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
26 changes: 26 additions & 0 deletions study/FragmentUI/basicfragment001/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.2"

defaultConfig {
applicationId "demo.fragmentui.com.basicfragment001"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
}
17 changes: 17 additions & 0 deletions study/FragmentUI/basicfragment001/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/anybus/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package demo.fragmentui.com.basicfragment001;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
20 changes: 20 additions & 0 deletions study/FragmentUI/basicfragment001/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="demo.fragmentui.com.basicfragment001">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package demo.fragmentui.com.basicfragment001;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import demo.fragmentui.com.basicfragment001.db.DB;

/**
* Created by anybus on 16/10/2.
*/
public class AddFragment extends Fragment {
private EditText editName;
private RadioGroup sex;
private RadioButton man,female;
private Button btnAdd;
private DB db;
private SQLiteDatabase dbWriter;
private String selectedSex;
private View.OnClickListener btnListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!checkEmpty()){
return;
}
ContentValues c = new ContentValues();
c.put("name",editName.getText().toString());
c.put("sex",selectedSex);
dbWriter.insert("user",null,c);
refreshListView();

}
};
private RadioGroup.OnCheckedChangeListener mChangeRadio = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == man.getId()){
selectedSex = man.getText().toString();
}
if (checkedId == female.getId()){
selectedSex = female.getText().toString();
}
}
};



private boolean checkEmpty(){
if (TextUtils.isEmpty(editName.getText())){
Toast.makeText(getContext(),"姓名不能为空",Toast.LENGTH_SHORT).show();
return false;
}
if (!man.isChecked() && !female.isChecked()){
Toast.makeText(getContext(),"性别不能为空",Toast.LENGTH_SHORT).show();
return false;
}
return true;
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.add_layout,container,false);
editName = (EditText) view.findViewById(R.id.edName);
sex = (RadioGroup) view.findViewById(R.id.group_sex);
man = (RadioButton) view.findViewById(R.id.radio_man);
female = (RadioButton) view.findViewById(R.id.radio_female);
btnAdd = (Button) view.findViewById(R.id.btnAdd);
db = new DB(getContext());
dbWriter = db.getWritableDatabase();
sex.setOnCheckedChangeListener(mChangeRadio);
btnAdd.setOnClickListener(btnListener);

return view;
}

private void refreshListView(){
getFragmentManager().beginTransaction()
.replace(R.id.listLayout,new UserListFragment()).commit();
editName.setText("");
editName.clearFocus();
sex.clearCheck();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package demo.fragmentui.com.basicfragment001;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportFragmentManager().beginTransaction().replace(R.id.addLayout,new AddFragment()).commit();
getSupportFragmentManager().beginTransaction().replace(R.id.listLayout,new UserListFragment()).commit();

}
}
Loading