2015. 11. 26. 11:58

Manifest 내 원하는 액티비티에 아래 필터 추가


<intent-filter>

        <category android:name="android.intent.category.DEFAULT" />

        <action android:name="android.intent.action.VIEW" />

        <data android:scheme="web" />

</intent-filter>


이후 웹에서 호출하는 부분


<a href="web://패키지명.액티비티명">

'안드로이드' 카테고리의 다른 글

뒤로가기 2회시 종료  (0) 2015.10.19
탭뷰 스크롤  (0) 2015.06.09
문자열로 클래스 만들기  (0) 2015.05.22
xml안에 xml넣기  (1) 2015.05.22
트리리스트 3단계 이상 내려가는 소스  (0) 2015.05.22
Posted by newkie
2015. 10. 19. 13:55

http://dsnight.tistory.com/14




BackPressCloseHandler.java

import android.app.Activity;
import android.widget.Toast;

public class BackPressCloseHandler {

	private long backKeyPressedTime = 0;
	private Toast toast;

	private Activity activity;

	public BackPressCloseHandler(Activity context) {
		this.activity = context;
	}

	public void onBackPressed() {
		if (System.currentTimeMillis() > backKeyPressedTime + 2000) {
			backKeyPressedTime = System.currentTimeMillis();
			showGuide();
			return;
		}
		if (System.currentTimeMillis() <= backKeyPressedTime + 2000) {
			activity.finish();
			toast.cancel();
		}
	}

	public void showGuide() {
		toast = Toast.makeText(activity,
				"\'뒤로\'버튼을 한번 더 누르시면 종료됩니다.", Toast.LENGTH_SHORT);
		toast.show();
	}
}



MainActivity.java

public class MainActivity extends Activity {

	private BackPressCloseHandler backPressCloseHandler;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		backPressCloseHandler = new BackPressCloseHandler(this);
	}

	@Override
	public void onBackPressed() {
		//super.onBackPressed();
		backPressCloseHandler.onBackPressed();
	}
}


'안드로이드' 카테고리의 다른 글

웹에서 액티비티 호출  (2) 2015.11.26
탭뷰 스크롤  (0) 2015.06.09
문자열로 클래스 만들기  (0) 2015.05.22
xml안에 xml넣기  (1) 2015.05.22
트리리스트 3단계 이상 내려가는 소스  (0) 2015.05.22
Posted by newkie
2015. 6. 9. 09:47


    <TabHost

        android:id="@+id/tabhost"

        android:layout_width="match_parent"

        android:layout_height="match_parent" >


        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:orientation="vertical" >

                <HorizontalScrollView

                    android:id="@+id/hsTab"

                    android:layout_width="match_parent"

                    android:layout_height="wrap_content"

                    android:fillViewport="true"

                    android:scrollbars="none" >


                    <TabWidget

                        android:id="@android:id/tabs"

                        android:layout_width="wrap_content"

                        android:layout_height="wrap_content" >

                    </TabWidget>

                </HorizontalScrollView>


            <FrameLayout

                android:id="@android:id/tabcontent"

                android:layout_width="match_parent"

                android:layout_height="match_parent" >


                    <include

                        android:id="@+id/iTab"

                        android:layout_width="match_parent"

                        android:layout_height="wrap_content"

                        layout="@layout/tab_layout" />

            </FrameLayout>

        </LinearLayout>

    </TabHost>


탭 4개쯤 되니까 스크롤 자동으로 생기고 옆으로 휙휙 넘어감.



'안드로이드' 카테고리의 다른 글

웹에서 액티비티 호출  (2) 2015.11.26
뒤로가기 2회시 종료  (0) 2015.10.19
문자열로 클래스 만들기  (0) 2015.05.22
xml안에 xml넣기  (1) 2015.05.22
트리리스트 3단계 이상 내려가는 소스  (0) 2015.05.22
Posted by newkie
2015. 5. 22. 11:06

http://sks3297.tistory.com/74

'안드로이드' 카테고리의 다른 글

뒤로가기 2회시 종료  (0) 2015.10.19
탭뷰 스크롤  (0) 2015.06.09
xml안에 xml넣기  (1) 2015.05.22
트리리스트 3단계 이상 내려가는 소스  (0) 2015.05.22
Strings 에서 parameter 넣기  (0) 2015.05.11
Posted by newkie
2015. 5. 22. 10:57

<include 

 layout="@layout/mylayout"

 android:id="@+id/iMyLayout"

 android:layout_width="match_parent"

 android:layout_height="wrap_content" />


햐 개꿀

'안드로이드' 카테고리의 다른 글

탭뷰 스크롤  (0) 2015.06.09
문자열로 클래스 만들기  (0) 2015.05.22
트리리스트 3단계 이상 내려가는 소스  (0) 2015.05.22
Strings 에서 parameter 넣기  (0) 2015.05.11
숏컷(바로가기) 생성하기  (0) 2014.12.22
Posted by newkie
2015. 5. 22. 10:19

탐색기 왼쪽처럼 나오는 소스

package com.newkie.testactivity;


import java.util.ArrayList;


import android.annotation.SuppressLint;

import android.app.Activity;

import android.content.Context;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.MotionEvent;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.ViewTreeObserver;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.ScrollView;

import android.widget.TextView;

import android.widget.Toast;


import com.newkie.testactivity.Product.SubCategory;

import com.newkie.testactivity.Product.SubCategory.SubSubCategory;

import com.newkie.testactivity.Product.SubCategory.SubSubCategory.ItemList;


public class MainActivity extends Activity

{

LinearLayout mLinearListView;

ScrollView svMain;


private Context mContext = this;

private boolean isFirstViewClick=false;

private boolean isSecondViewClick=false;

private boolean isThirdViewClick=false;

ArrayList<Product> pProductArrayList=new ArrayList<Product>();

ArrayList<SubCategory> pSubItemArrayList=new ArrayList<SubCategory>();

ArrayList<SubCategory> pSubItemArrayList2=new ArrayList<SubCategory>();

ArrayList<SubSubCategory> pSubSubItemArrayList=new ArrayList<SubSubCategory>();

ArrayList<SubSubCategory> pSubSubItemArrayList2=new ArrayList<SubSubCategory>();

ArrayList<SubSubCategory> pSubSubItemArrayList3=new ArrayList<SubSubCategory>();


@Override

protected void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

SetTempValue();

initValue();

}

@SuppressLint("InflateParams")

private void initValue()

{

mLinearListView = (LinearLayout) findViewById(R.id.llMain);

svMain = (ScrollView)findViewById(R.id.svMain);


SetTempValue();


//Adding Items into List


//First Level

for (int i = 0; i < pProductArrayList.size(); i++)

{

LayoutInflater inflater = null;

inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View mLinearView = inflater.inflate(R.layout.row_first, null);


final TextView mProductName = (TextView) mLinearView.findViewById(R.id.textViewName);

final LinearLayout mLinearFirstArrow=(LinearLayout)mLinearView.findViewById(R.id.linearFirst);

final ImageView mImageArrowFirst=(ImageView)mLinearView.findViewById(R.id.imageFirstArrow);

final LinearLayout mLinearScrollSecond=(LinearLayout)mLinearView.findViewById(R.id.linear_scroll);


if(isFirstViewClick==false)

{

mLinearScrollSecond.setVisibility(View.GONE);

mImageArrowFirst.setBackgroundResource(R.drawable.folder_close);

}

else

{

mLinearScrollSecond.setVisibility(View.VISIBLE);

mImageArrowFirst.setBackgroundResource(R.drawable.folder_open);

}


mLinearFirstArrow.setOnClickListener(new OnClickListener()

{

@Override

public void onClick(View v)

{

if(mLinearScrollSecond.getVisibility() == View.GONE)

{

isFirstViewClick=true;

mImageArrowFirst.setBackgroundResource(R.drawable.folder_open);

mLinearScrollSecond.setVisibility(View.VISIBLE);


}

else

{

isFirstViewClick=false;

mImageArrowFirst.setBackgroundResource(R.drawable.folder_close);

mLinearScrollSecond.setVisibility(View.GONE);

}

}

});


final String name = pProductArrayList.get(i).getpName();

mProductName.setText(name);


//Second Level

for (int j = 0; j < pProductArrayList.get(i).getmSubCategoryList().size(); j++)

{

LayoutInflater inflater2 = null;

inflater2 = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View mLinearView2 = inflater2.inflate(R.layout.row_middle, null);


TextView mSubItemName = (TextView) mLinearView2.findViewById(R.id.textViewName);

final LinearLayout mLinearSecondArrow=(LinearLayout)mLinearView2.findViewById(R.id.linearMiddle);

final ImageView mImageArrowSecond=(ImageView)mLinearView2.findViewById(R.id.imageMiddleArrow);

final LinearLayout mLinearScrollThird=(LinearLayout)mLinearView2.findViewById(R.id.linear_scroll_middle);


if(isSecondViewClick==false)

{

mLinearScrollThird.setVisibility(View.GONE);

mImageArrowSecond.setBackgroundResource(R.drawable.folder_close);

}

else

{

mLinearScrollThird.setVisibility(View.VISIBLE);

mImageArrowSecond.setBackgroundResource(R.drawable.folder_open);

}


mLinearSecondArrow.setOnClickListener(new OnClickListener()

{

@Override

public void onClick(View v)

{

if(mLinearScrollThird.getVisibility() == View.GONE)

{

isSecondViewClick=true;

mImageArrowSecond.setBackgroundResource(R.drawable.folder_open);

mLinearScrollThird.setVisibility(View.VISIBLE);

}

else

{

isSecondViewClick=false;

mImageArrowSecond.setBackgroundResource(R.drawable.folder_close);

mLinearScrollThird.setVisibility(View.GONE);

}

}

});



final String catName = pProductArrayList.get(i).getmSubCategoryList().get(j).getpSubCatName();

mSubItemName.setText(catName);


//Third Level

for (int k = 0; k < pProductArrayList.get(i).getmSubCategoryList().get(j).getmSubSubCategoryList().size(); k++)

{

LayoutInflater inflater3 = null;

inflater3 = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View mLinearView3 = inflater3.inflate(R.layout.row_middle, null);


TextView mSubSubItemName = (TextView) mLinearView3.findViewById(R.id.textViewName);

final LinearLayout mLinearThirdArrow=(LinearLayout)mLinearView3.findViewById(R.id.linearMiddle);

final ImageView mImageArrowThird=(ImageView)mLinearView3.findViewById(R.id.imageMiddleArrow);

final LinearLayout mLinearScrollFourth=(LinearLayout)mLinearView3.findViewById(R.id.linear_scroll_middle);


if(isThirdViewClick==false)

{

mLinearScrollFourth.setVisibility(View.GONE);

mImageArrowThird.setBackgroundResource(R.drawable.folder_close);

}

else

{

mLinearScrollFourth.setVisibility(View.VISIBLE);

mImageArrowThird.setBackgroundResource(R.drawable.folder_open);

}


mLinearThirdArrow.setOnClickListener(new OnClickListener()

{

@Override

public void onClick(View v)

{

if(mLinearScrollFourth.getVisibility() == View.GONE)

{

isThirdViewClick=true;

mImageArrowThird.setBackgroundResource(R.drawable.folder_open);

mLinearScrollFourth.setVisibility(View.VISIBLE);

}

else

{

isThirdViewClick=false;

mImageArrowThird.setBackgroundResource(R.drawable.folder_close);

mLinearScrollFourth.setVisibility(View.GONE);

}

}

});


final String catCatName = pProductArrayList.get(i).getmSubCategoryList().get(j).getmSubSubCategoryList().get(k).getpSubSubCatName();

mSubSubItemName.setText(catCatName);


//Fourth Level

for (int l = 0; l < pProductArrayList.get(i).getmSubCategoryList().get(j).getmSubSubCategoryList().get(k).getmItemListArray().size(); l++)

{

LayoutInflater inflater4 = null;

inflater4 = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View mLinearView4 = inflater4.inflate(R.layout.row_last, null);


TextView mItemName = (TextView) mLinearView4.findViewById(R.id.textViewItemName);

TextView mItemPrice = (TextView) mLinearView4.findViewById(R.id.textViewItemPrice);

final String itemName = pProductArrayList.get(i).getmSubCategoryList().get(j).getmSubSubCategoryList().get(k).getmItemListArray().get(l).getItemName();

final String itemFname = pProductArrayList.get(i).getmSubCategoryList().get(j).getmSubSubCategoryList().get(k).getmItemListArray().get(l).getItemPrice();

mItemName.setText(itemName);

mItemPrice.setText(itemFname);


mLinearView4.setOnClickListener(new OnClickListener()

{

@Override

public void onClick(View v)

{

Toast.makeText(mContext, itemName+"입니다.", Toast.LENGTH_SHORT).show();

}

});

mLinearScrollFourth.addView(mLinearView4);

}

mLinearScrollThird.addView(mLinearView3);

}

mLinearScrollSecond.addView(mLinearView2);

}

mLinearListView.addView(mLinearView);

}


svMain.setOnTouchListener(new View.OnTouchListener()

{

@Override

public boolean onTouch(View v, MotionEvent event)

{

return false;

}

});

}


private void SetTempValue()

{

ArrayList<ItemList> mItemListArray=new ArrayList<ItemList>();

mItemListArray.add(new ItemList("나", "1"));

mItemListArray.add(new ItemList("는", "2"));


ArrayList<ItemList> mItemListArray2=new ArrayList<ItemList>();

mItemListArray2.add(new ItemList("말", "3"));

mItemListArray2.add(new ItemList("단", "4"));


ArrayList<ItemList> mItemListArray3=new ArrayList<ItemList>();

mItemListArray3.add(new ItemList("입", "5"));

mItemListArray3.add(new ItemList("니", "6"));


ArrayList<ItemList> mItemListArray4=new ArrayList<ItemList>();

mItemListArray4.add(new ItemList("다", "7"));

mItemListArray4.add(new ItemList("!", "8"));


ArrayList<ItemList> mItemListArray5=new ArrayList<ItemList>();

mItemListArray5.add(new ItemList("말단", "9"));

mItemListArray5.add(new ItemList("말단", "9"));


pSubItemArrayList=new ArrayList<SubCategory>();

pSubItemArrayList2=new ArrayList<SubCategory>();

pSubSubItemArrayList=new ArrayList<SubSubCategory>();

pSubSubItemArrayList2=new ArrayList<SubSubCategory>();

pSubSubItemArrayList3=new ArrayList<SubSubCategory>();


pSubSubItemArrayList.add(new SubSubCategory("1-1-1", false,  mItemListArray));

pSubSubItemArrayList.add(new SubSubCategory("1-1-2", false,  mItemListArray2));

pSubSubItemArrayList2.add(new SubSubCategory("1-2-1", false,  mItemListArray3));

pSubSubItemArrayList2.add(new SubSubCategory("1-2-2", false,  mItemListArray4));

pSubSubItemArrayList3.add(new SubSubCategory("2-1-1", false,  mItemListArray5));

pSubSubItemArrayList3.add(new SubSubCategory("2-1-2", false,  mItemListArray5));


pSubItemArrayList.add(new SubCategory("1-1", false, pSubSubItemArrayList));

pSubItemArrayList.add(new SubCategory("1-2", false, pSubSubItemArrayList2));

pSubItemArrayList2.add(new SubCategory("2-1", false, pSubSubItemArrayList3));


pProductArrayList=new ArrayList<Product>();

pProductArrayList.add(new Product("1", false, pSubItemArrayList));

pProductArrayList.add(new Product("2", false, pSubItemArrayList2));

}


}





Product.java



// first level item

public class Product

{

private String pName;

private boolean isFirstClicked = false;


private ArrayList<SubCategory> mSubCategoryList;


public Product(String pName, boolean isFirstClicked, ArrayList<SubCategory> mSubCategoryList)

{

super();

this.pName = pName;

this.isFirstClicked = isFirstClicked;

this.mSubCategoryList = mSubCategoryList;

}


public String getpName()

{

return pName;

}


public void setpName(String pName)

{

this.pName = pName;

}


public boolean isFirstClicked()

{

return isFirstClicked;

}


public void setFirstClicked(boolean isFirstClicked)

{

this.isFirstClicked = isFirstClicked;

}


public ArrayList<SubCategory> getmSubCategoryList()

{

return mSubCategoryList;

}


public void setmSubCategoryList(ArrayList<SubCategory> mSubCategoryList)

{

this.mSubCategoryList = mSubCategoryList;

}



// second level item

public static class SubCategory

{

private String pSubCatName;

private boolean isSecondClicked = false;


private ArrayList<SubSubCategory> mSubSubCategoryList;


public SubCategory(String pSubCatName, boolean isSecondClicked,

ArrayList<SubSubCategory> mSubSubCategoryList)

{

super();

this.pSubCatName = pSubCatName;

this.isSecondClicked = isSecondClicked;

this.mSubSubCategoryList = mSubSubCategoryList;

}


public String getpSubCatName()

{

return pSubCatName;

}


public void setpSubCatName(String pSubCatName)

{

this.pSubCatName = pSubCatName;

}


public boolean isSecondClicked() {

return isSecondClicked;

}


public void setSecondClicked(boolean isSecondClicked) {

this.isSecondClicked = isSecondClicked;

}


public ArrayList<SubSubCategory> getmSubSubCategoryList()

{

return mSubSubCategoryList;

}


public void setmItemListArray(ArrayList<SubSubCategory> mSubSubCategoryList)

{

this.mSubSubCategoryList = mSubSubCategoryList;

}


// third level item

public static class SubSubCategory

{

private String pSubSubCatName;

private boolean isThirdClicked = false;

private ArrayList<ItemList> mItemListArray;


public SubSubCategory(String pSubSubCatName, boolean isThirdClicked,

ArrayList<ItemList> mItemListArray)

{

super();

this.pSubSubCatName = pSubSubCatName;

this.isThirdClicked = isThirdClicked;

this.mItemListArray = mItemListArray;

}


public String getpSubSubCatName()

{

return pSubSubCatName;

}


public void setpSubSubCatName(String pSubSubCatName)

{

this.pSubSubCatName = pSubSubCatName;

}


public boolean isThirdClicked() {

return isThirdClicked;

}


public void setThirdClicked(boolean isThirdClicked) {

this.isThirdClicked = isThirdClicked;

}


public ArrayList<ItemList> getmItemListArray()

{

return mItemListArray;

}


public void setmItemListArray(ArrayList<ItemList> mItemListArray)

{

this.mItemListArray = mItemListArray;

}



// 4th level item


public static class ItemList

{


private String itemName;

private String itemPrice;


public ItemList(String itemName, String itemPrice)

{

super();

this.itemName = itemName;

this.itemPrice = itemPrice;

}


public String getItemName()

{

return itemName;

}


public void setItemName(String itemName)

{

this.itemName = itemName;

}


public String getItemPrice()

{

return itemPrice;

}


public void setItemPrice(String itemPrice)

{

this.itemPrice = itemPrice;

}


}


}


}


}



activity_main.xml


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:id="@+id/svMain"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    tools:context="${relativePackage}.${activityClass}" >


    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="vertical" >


        <LinearLayout

            android:id="@+id/llMain"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:orientation="vertical" />

    </LinearLayout>


</ScrollView>



row_first.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:background="@android:color/white"

    android:orientation="vertical" >


    <LinearLayout

        android:id="@+id/linearFirst"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:gravity="center_vertical"

        android:minHeight="40dp" >


        <ImageView

            android:id="@+id/imageFirstArrow"

            android:layout_width="20dp"

            android:layout_height="20dp"

            android:contentDescription="@string/def_folder" />


        <TextView

            android:id="@+id/textViewName"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:paddingEnd="0dp"

            android:paddingLeft="5dp"

            android:paddingRight="0dp"

            android:paddingStart="5dp"

            android:text="@string/def_title"

            android:textColor="#000000"

            android:textSize="20sp" />

        <!--

        <TextView

            android:id="@+id/textViewName"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_alignParentLeft="true"

            android:layout_marginLeft="10dp"

            android:text="TextView"

            android:textColor="@android:color/white"

            android:textSize="22sp" />


        <ImageView

            android:id="@+id/imageFirstArrow"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_alignParentRight="true"

            android:layout_marginRight="5dp" />

        -->

    </LinearLayout>


    <LinearLayout

        android:id="@+id/linear_scroll"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_marginLeft="10dp"

        android:layout_marginStart="10dp"

        android:background="@android:color/white"

        android:orientation="vertical" />


    <View

        android:layout_width="match_parent"

        android:layout_height="1dp"

        android:background="@android:color/white" />


</LinearLayout>


row_middle.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:background="@android:color/white"

    android:orientation="vertical" >


    <LinearLayout

        android:id="@+id/linearMiddle"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:gravity="center_vertical"

        android:minHeight="40dp" >


        <ImageView

            android:id="@+id/imageMiddleArrow"

            android:layout_width="20dp"

            android:layout_height="20dp"

            android:contentDescription="@string/def_folder" />


        <TextView

            android:id="@+id/textViewName"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:paddingEnd="0dp"

            android:paddingLeft="5dp"

            android:paddingRight="0dp"

            android:paddingStart="5dp"

            android:text="@string/def_title"

            android:textColor="#000000"

            android:textSize="20sp" />

        <!--

        <TextView

            android:id="@+id/textViewName"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_alignParentLeft="true"

            android:layout_marginLeft="10dp"

            android:text="TextView"

            android:textColor="@android:color/white"

            android:textSize="22sp" />


        <ImageView

            android:id="@+id/imageSecondArrow"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_alignParentRight="true"

            android:layout_marginRight="5dp" />

        -->

    </LinearLayout>


    <LinearLayout

        android:id="@+id/linear_scroll_middle"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_marginLeft="10dp"

        android:layout_marginStart="10dp"

        android:background="@android:color/white"

        android:orientation="vertical" />


    <View

        android:layout_width="match_parent"

        android:layout_height="1dp"

        android:background="@android:color/white" />


</LinearLayout>


row_last.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:gravity="center_vertical"
    android:minHeight="40dp"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imageFourthArrow"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:contentDescription="@string/def_folder"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textViewItemName"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingEnd="0dp"
        android:paddingLeft="5dp"
        android:paddingRight="0dp"
        android:paddingStart="5dp"
        android:text="@string/def_name"
        android:textColor="#000000"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textViewItemPrice"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingEnd="0dp"
        android:paddingLeft="5dp"
        android:paddingRight="0dp"
        android:paddingStart="5dp"
        android:text="@string/def_fname"
        android:textColor="#000000"
        android:textSize="20sp" />

</LinearLayout>


Expandable ListView가 너무나도 안되서


리스트뷰 아니고 레이아웃으로 구현됨....

'안드로이드' 카테고리의 다른 글

문자열로 클래스 만들기  (0) 2015.05.22
xml안에 xml넣기  (1) 2015.05.22
Strings 에서 parameter 넣기  (0) 2015.05.11
숏컷(바로가기) 생성하기  (0) 2014.12.22
파일 탐색기  (0) 2014.10.02
Posted by newkie
2015. 5. 11. 18:02

Strings에

<string name="params">param1 is %1$s and param2 is %2$s</string>


소스에 쓸때

getString(R.string.params , "new", "kie");


결과

param1 is new and param2 is kie



'안드로이드' 카테고리의 다른 글

xml안에 xml넣기  (1) 2015.05.22
트리리스트 3단계 이상 내려가는 소스  (0) 2015.05.22
숏컷(바로가기) 생성하기  (0) 2014.12.22
파일 탐색기  (0) 2014.10.02
어플리케이션 중복 실행 방지  (0) 2014.08.19
Posted by newkie
2014. 12. 22. 11:15
public static void addShortcut(Context context)
{
if(!pref.getBoolean("addshotcut",false))
{
editor.putBoolean("addshotcut", true);
editor.commit();

Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shortcutIntent.setClassName(context, context.getClass().getName());
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
context.getResources().getString(R.string.app_name)); 
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(context,
R.drawable.ic_launcher));
intent.putExtra("duplicate", false);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");

context.sendBroadcast(intent);
}
}



Manifest에


    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />


추가

Posted by newkie
2014. 10. 2. 18:29

구현할 일이 있어서 소스 찾아봤는데


뭐가 그리 복잡하게 덕지덕지 붙여 놨는지


CCCV 못하게 할 거면 왜 써놓은 건지


제일 참고할 만한 자료는 퀴즈처럼 중간중간에 비워놓은 것을 짜증나서 뜯어고쳐서 적어둠.



MainActivity.java


package com.newkie.fileexplorer;


import java.io.File;

import java.util.ArrayList;

import java.util.List;


import android.app.Activity;

import android.content.Context;

import android.os.Bundle;

import android.os.Environment;

import android.util.Log;

import android.view.View;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import android.widget.TextView;

import android.widget.Toast;


public class MainActivity extends Activity

{

    private String mFileName;

    private ListView lvFileControl;

    private Context mContext = this;


    private List<String> lItem = null;

    private List<String> lPath = null;

    private String mRoot = Environment.getExternalStorageDirectory().getAbsolutePath();

    private TextView mPath;


    

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        mPath = (TextView) findViewById(R.id.tvPath);

        lvFileControl = (ListView)findViewById(R.id.lvFileControl);

        getDir(mRoot);

        

        lvFileControl.setOnItemClickListener(new OnItemClickListener(){

@Override

public void onItemClick(AdapterView<?> parent, View v, int position, long id)

{

File file = new File(lPath.get(position));


       if (file.isDirectory())

       {

           if (file.canRead())

               getDir(lPath.get(position));

           else

           {

            Toast.makeText(mContext, "No files in this folder.", Toast.LENGTH_SHORT).show();

           }

       }

       else

       {

           mFileName = file.getName();

           Log.i("Test","ext:"+mFileName.substring(mFileName.lastIndexOf('.') + 1, mFileName.length()));

       }

}

});

    }


    private void getDir(String dirPath)

    {

        mPath.setText("Location: " + dirPath);


        lItem = new ArrayList<String>();

        lPath = new ArrayList<String>();


        File f = new File(dirPath);

        File[] files = f.listFiles();


        if (!dirPath.equals(mRoot))

        {

            //item.add(root); //to root.

            //path.add(root);


            lItem.add("../"); //to parent folder

            lPath.add(f.getParent());

        }


        for (int i = 0; i < files.length; i++)

        {

            File file = files[i];

            lPath.add(file.getAbsolutePath());


            if (file.isDirectory())

                lItem.add(file.getName() + "/");

            else

                lItem.add(file.getName());

        }


        ArrayAdapter<String> fileList = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, lItem);

        lvFileControl.setAdapter(fileList);

    }

}



activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical" >


    <TextView

        android:id="@+id/tvPath"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content" />


    <ListView

        android:id="@+id/lvFileControl"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:divider="#ffffff" >

    </ListView>

</LinearLayout>



그리고 MANIFEST에 


    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


추가한다.


소스상에선 WRITE는 쓸 일이 없으니 빼도 무관.




간단한 소스이니 좀만 들여다보면 세부 기능 구현이 가능할 것.(root를 바꾼다거나 확장자에 따라서 눌렀을때 처리한다거나)

Posted by newkie
2014. 8. 19. 11:29

USB Connector를 이용한 어플 개발 중 USB를 꽂을때마다 해당 앱이 자동실행+중복실행되었다.


singleinstance singletask singletop 전부 무용지물.


별별 방법을 다 쓰다가 소스상으로 원천봉쇄하는데 성공


private static boolean isAppRunning = false;

private boolean isDuple = false;


@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

Log.i(TAG,"onCreate");

setContentView(R.layout.splash);

if(isAppRunning)

{

isDuple = true;

finish();

}

else

{

isAppRunning = true;

//이후 정상적으로 실행할 부분

//

//

}

}



@Override

public void onDestroy()

{

super.onDestroy();

Log.i(TAG,"onDestroy");

if(isDuple)

{


}

else

{

isAppRunning = false;

}

}


마지막은 !isDuple로 바로 끝나도 될 것.

static변수는 어플이 중복실행되어도 변하지 않는다는 점을 이용했다.

이제 고민은 어플이 실행 중 사망하셨을 때 이 루틴이 어떻게 처리될 것인가 하는 것.


Posted by newkie